Hard Coding Google Maps Block into theme page type.

Permalink 1 user found helpful
Im new to Concrete5 so bear with me if this is obvious. Im using Concrete 5.6.0.2.

Im creating a theme for a page type that has an address and I want to hard code in a google map block. Ive looked at the API and previous posts and have gotten the following:
$bt_map = BlockType::getByHandle('google_map');
$bt_map->controller->title = $c->getAttribute('event_location');
$bt_map->controller->location = (string)$c->getAttribute('event_address');
$bt_map->controller->zoom = 15;
$bt_map->render('view');


Previous examples have said that this also requires an API key etc but since using the Google Maps API no longer requires one and those examples are from last year, I stripped that stuff out.

The problem Im getting is that the title renders fine but the map doesnt get rendered in the googleMapCanvas div. I then checked the bottom list of scripts and the google maps js doesnt seem to be included in.

Is this something I have to do manually or have I not implemented the block correctly? If I have to do it manually, how do I go about it?

Thanks very much in advance.

 
planist1 replied on at Permalink Reply
planist1
Try putting
<?php
$this->addHeaderItem(Loader::helper('html')->javascript('jquery.js'), 'CORE');
?>
on the page?

See here:
http://www.concrete5.org/community/forums/usage/google-map-block-bl...

Hope this helps.
chrisg replied on at Permalink Reply
Thanks for the help. It was including the jquery js, just not the google maps js. I ended up getting it working with:

<?php
  defined('C5_EXECUTE') or die("Access Denied.");
  $address = $c->getAttribute('event_address');
  //setup google map
  $bt_map = BlockType::getByHandle('google_map');
  $bt_map->controller->title = $c->getAttribute('event_location');
  $bt_map->controller->location = (string)$address;
  $coords = $bt_map->controller->lookupLatLong((string)$address);
  $bt_map->controller->latitude = floatval($coords['lat']);
  $bt_map->controller->longitude = floatval($coords['lng']);
  $bt_map->controller->zoom = 15;
  $this->inc('elements/header.php');
?>
...
Page Type HTML


Thanks!
McArtney82 replied on at Permalink Reply
I know this is somewhat outdated now but in case anyone else is looking at this, because this drove me crazy. I had to add the footer to my code too as the core Google Maps block adds some code to display the map in your footer.

This website stores cookies on your computer. These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media. To find out more about the cookies we use, see our Privacy Policy.