Google Map in Template

Permalink 1 user found helpful
Hello, all. I've created a special template in my site for Locations. I've created and assigned to that template a custom attribute fields called Address.

Can anyone tell me if it's possible to:

1) hard-code into my Location template a Google Map block, and

2) pull the address from that custom field.

I've been manually adding the Google Map block into each page, but since the every location page consists of the Location Name, Address and Google Map block, I thought it might be easier to build these fields into the template.

Thanks

 
kirkroberts replied on at Permalink Reply
kirkroberts
I'm using code similar to this to get a Google map in my template, populating the location from page properties.

$bt_map = BlockType::getByHandle('google_map');
$bt_map->controller->title = 'YOUR_TITLE';
$api_key = 'YOUR_API_KEY'; // get this from Google
$bt_map->controller->api_key = $api_key;
$location = 'YOUR_LOCATION'; // street address, city, ST         
$geoCodeHelper = new GoogleGeoCodeHelper( $api_key );
$geoCodeHelper->loadGeoCodeData($location);
$coords=$geoCodeHelper->getCoords();
$bt_map->controller->latitude = floatval($coords[1]);
$bt_map->controller->longitude = floatval($coords[0]);
$bt_map->controller->zoom = 16; // 0 - 17, 17 is closest
$bt_map->render('view');

Hope that helps!
Metaglyphics replied on at Permalink Reply
Thanks for the response. I figured out more or less the same thing. Here's how it ended up:

http://landaulawyersleague.com/basketball/courts/...

I used a list summary with a lightbox and created some custome page properties to supply the address.
kirkroberts replied on at Permalink Reply
kirkroberts
Yeah, I figured you had probably moved on by now, but since I found your post looking for the answer I thought others might as well.

So now they have an answer to help them out. Just one approach to consider.

Your solution looks good!
goldfish replied on at Permalink Reply
goldfish
Thank you - enormously helpful. I had tried this and got stuck on getting the geocoding to work.