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

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;

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.

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

See here:

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:

  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;
Page Type HTML

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.