Google Maps hardcoding and integration

Permalink
I have a custom block which includes a lot of info, the block is on a page that is generated through a listing system. I would like to add a Google map into this block. The location of the map is determined by a page attribute. However i have the following issues:

I've tried including the following code:
<?php
$bt_map = BlockType::getByHandle('google_map');
$bt_map->controller->title = 'test';
$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;
$bt_map->render('view');
?>
However this only creates an empty div.

I tried following this post:https://www.concrete5.org/community/forums/customizing_c5/hard-codin... But with no luck.

I've seen others say they ended up implementing their own google maps javascript. However when i try to do this, i get this javascript error in the console: "You have included the Google Maps API multiple times on this page. This may cause unexpected errors."

All i am looking for is to include a google map, in my block

lundco99
 
JohntheFish replied on at Permalink Reply
JohntheFish
If your code is in a block view, then it is too late. The assets for the map need to be loaded when the block controller is loaded.
lundco99 replied on at Permalink Reply
lundco99
In that case, maybe the best idea would be to code the map myself. But i am getting the problem where i cannot load a google maps script, since it tells me "You already have a maps script". And when i try to call the map without including the script on my own, it tells me that "google" does not exist, when i try to call google.maps.Map().

Any suggestions? :-)
lundco99 replied on at Permalink Reply 3 Attachments
lundco99
I've successfully implemented the map by using a pagetype instead of a block, and with the help from this post:https://www.concrete5.org/community/forums/customizing_c5/hard-codin...

However i am running into the issue where, my google map does not render properly. Please look at attached screenshots, where i try to navigate the map, and the tiles disappear and appear spontaneously.