Tuesday 16 August 2011

Load event for Google Maps Javascript API V3

Use this JavaScript event listener to know when your Google Map finishes initialising.

google.maps.event.addListener(map, 'idle', function() {
   ...
});

REFERENCES
http://code.google.com/p/gmaps-api-issues/issues/detail?id=1516

2 comments:

  1. Your code should be upgraded, because it fires every time you load the map, drag the map, zoom, etc...

    google.maps.event.addListener(GMap, 'idle', function(){
    if(!mapLoaded){
    $('#google_map').trigger('mapLoaded');
    mapLoaded = true;

    //do my stuff
    }
    });$('#map_canvas').bind('mapLoaded', function(){console.log('The mapLoaded event has occurred!!!');});

    ReplyDelete
  2. You can use the addListenerOnce event handler, so that it will trigger the event only once. https://developers.google.com/maps/documentation/javascript/reference?hl=en#MapsEventListener

    ReplyDelete