Hard Coding Google Maps Block into theme page type.
Permalink 1 user found helpfulIm 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.
<?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!
See here:
http://www.concrete5.org/community/forums/usage/google-map-block-bl...
Hope this helps.