Google Maps API v2 load() event not firing

耗尽温柔 提交于 2019-12-08 07:31:16

问题


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" );
}

回答1:


The load event is not firing because it gets triggered soon after you call setCenter(), and at that time your event listener is not attached yet. You can see the event being triggered 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 for the load event to start adding markers to the map.



来源:https://stackoverflow.com/questions/3682017/google-maps-api-v2-load-event-not-firing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!