I’m improving the Google Maps API V2 integration in our web app and I’d like my main page to know when Google Maps has finished loading everything so I can then set some markers.
I notice there’s a load() event but I can never seem to get it fire.
Here’s 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" );
}
The
loadevent is not firing because it gets triggered soon after you callsetCenter(), and at that time your event listener is not attached yet. You can see the event being triggered in the following example:Note that there is no need to listen for the
loadevent to start adding markers to the map.