How can I check whether Google Maps is fully loaded?

后端 未结 9 1159
野性不改
野性不改 2020-11-22 13:44

I’m embedding Google Maps into my web site. Once Google Maps is loaded, I need to kick off a few JavaScript processes.

Is there a way to auto-detect when Goo

相关标签:
9条回答
  • 2020-11-22 14:39

    I'm creating html5 mobile apps and I noticed that the idle, bounds_changed and tilesloaded events fire when the map object is created and rendered (even if it is not visible).

    To make my map run code when it is shown for the first time I did the following:

    google.maps.event.addListenerOnce(map, 'tilesloaded', function(){
        //this part runs when the mapobject is created and rendered
        google.maps.event.addListenerOnce(map, 'tilesloaded', function(){
            //this part runs when the mapobject shown for the first time
        });
    });
    
    0 讨论(0)
  • 2020-11-22 14:41

    If you're using the Maps API v3, this has changed.

    In version 3, you essentially want to set up a listener for the bounds_changed event, which will trigger upon map load. Once that has triggered, remove the listener as you don't want to be informed every time the viewport bounds change.

    This may change in the future as the V3 API is evolving :-)

    0 讨论(0)
  • 2020-11-22 14:44

    GMap2::tilesloaded() would be the event you're looking for.

    See GMap2.tilesloaded for references.

    0 讨论(0)
提交回复
热议问题