Maps API v2 () loading event does not fire

I am improving the integration of the Google Maps API V2 in our web application, and I would like my home page to know when Google Maps has finished loading everything, so I can set some markers.

I noticed a load () event there , but I can never fire it.

Here is the code I'm using

if( GBrowserIsCompatible() ) { map = new GMap2(container); map.setCenter(new GLatLng(INITIAL_LATITUDE,INITIAL_LONGITUDE), INITIAL_ZOOM); GEvent.addListener(map, "load", pluginLoaded ); } 

...

 function pluginLoaded() { alert( "pluginLoaded" ); } 
+1
source share
1 answer

The load event does not setCenter() because it fires immediately after calling setCenter() , and at that time your event listener is not connected yet. You can see that the event is fired in the following example:

 if (GBrowserIsCompatible()) { var map = new GMap2(document.getElementById("map")); GEvent.addListener(map, "load", function() { alert("Map Loaded"); }); map.setCenter(new GLatLng(37.4419, -122.1419), 13); } 

Note that there is no need to listen to the load event to start adding markers to the map.

+5
source

All Articles