Simple Google Maps object for use with ajax maps

Comparing #1 with #2

Revision #2 was created by Chris Backhouse Chris Backhouse on Oct 5, 2015, 11:12:49 AM.

correct typos and add comments

Content


 
The Google mapping extension by Dos Amigos ([link](https://github.com/2amigos/yii2-google-maps-library "link")) is really great but there are difficulties with Google maps when you want to manipulate your map object with Ajax.

Thanks to some core code from Dos Amigos, I have fashioned a simpler way to manage ajax manipulation of Google maps.
[...]
The method described here enables you to create a map canvas and then update it over time with Ajax calls.

First, create a
n javascript file with the following code

~~~
[...]
gmap0.clearMarkers();
$.getScript( link , function( data, textStatus, jqxhr ) {
           // refresh map to get it to display new markers
 
              // you can also use this. if you need to refresh the map eg: when changing tabs
 
setTimeout(function() {map = gmap0.getMap(); var center = map.getCenter(); google.maps.event.trigger(map, 'resize'); map.setCenter(center);}, 500);
});
~~~

example of action-that-returns-just-javascript
[...]