This was bothering me for a while with GMaps v3.(GMaps v3让我困扰了一段时间。)
I found a way to do it like this:(我找到了这样做的方法:)
google.maps.event.addListenerOnce(map, 'idle', function(){
// do something only the first time the map is loaded
});
The "idle" event is triggered when the map goes to idle state - everything loaded (or failed to load).(当地图进入空闲状态时会触发“空闲”事件 - 所有内容都已加载(或无法加载)。) I found it to be more reliable then tilesloaded/bounds_changed and using addListenerOnce
method the code in the closure is executed the first time "idle" is fired and then the event is detached.(我发现它比tilesload / bounds_changed更可靠,并且使用addListenerOnce
方法,在第一次触发“idle”时执行闭包中的代码,然后分离事件。)
See also the events section in the Google Maps Reference.(另请参阅Google地图参考中的事件部分 。) 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…