Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
314 views
in Technique[技术] by (71.8m points)

javascript - 如何检查Google地图是否已满载?(How can I check whether Google Maps is fully loaded?)

I'm embedding Google Maps into my web site.(我正在将Google地图嵌入我的网站。)

Once Google Maps is loaded, I need to kick off a few JavaScript processes.(加载Google地图后,我需要启动一些JavaScript流程。) Is there a way to auto-detect when Google Maps has fully loaded, including tile downloads and all?(有没有办法在Google地图完全加载时自动检测,包括平铺下载等等?) A tilesloaded() method exists that is supposed to accomplish exactly this task but it does not work .(存在一个tilesloaded()方法,该方法应该完成此任务,但它不起作用 。)   ask by translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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地图参考中的事件部分 。)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...