Google Maps API v2 load()事件未触发 [英] Google Maps API v2 load() event not firing

查看:109
本文介绍了Google Maps API v2 load()事件未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在改善Web应用程序中的Google Maps API V2集成,我想让我的主页知道Google Maps何时完成所有加载,因此我可以设置一些标记.

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.

我注意到有一个 load()事件,但我似乎永远无法解决.

I notice there's a load() event but I can never seem to get it fire.

这是我正在使用的代码

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

推荐答案

load事件未触发,因为它是在调用setCenter()之后立即触发的,当时您的事件侦听器尚未连接.您可以在以下示例中看到事件被触发:

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

请注意,无需监听load事件即可开始向地图添加标记.

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

这篇关于Google Maps API v2 load()事件未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆