问题描述
我正在将 Google 地图嵌入到我的网站中.加载 Google 地图后,我需要启动一些 JavaScript 进程.
I’m embedding Google Maps into my web site. Once Google Maps is loaded, I need to kick off a few JavaScript processes.
有没有办法自动检测 Google 地图何时完全加载,包括图块下载等?
存在一个 tilesloaded()
方法,它应该完全完成这个任务,但是 它不起作用.>
A tilesloaded()
method exists that is supposed to accomplish exactly this task but it does not work.
推荐答案
这让 GMaps v3 困扰了我一段时间.
This was bothering me for a while with 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
});
当地图进入空闲状态时触发空闲"事件 - 一切都已加载(或加载失败).我发现它比 tileloaded/bounds_changed 更可靠,并且使用 addListenerOnce
方法,闭包中的代码在第一次触发空闲"然后分离事件时执行.
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.
另请参阅 Google 中的事件部分地图参考.
See also the events section in the Google Maps Reference.
这篇关于如何检查谷歌地图是否已满载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!