如何检查Google地图是否已完全加载? [英] How can I check whether Google Maps is fully loaded?

查看:164
本文介绍了如何检查Google地图是否已完全加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将Google地图嵌入我的网站。加载Google地图后,我需要启动一些JavaScript流程。

有没有一种方法可以在Google地图完全加载时自动检测,包括瓦片下载和所有?



tilesloaded()方法存在,应该完成这个任务但它不起作用 这让我在GMaps v3上困扰了一段时间。



我找到了这样做的方法:

  google.maps.event.addListenerOnce(map,'idle',function(){
//只在第一次加载地图时执行某些操作
}) ;

地图进入闲置状态时会触发空闲事件 - 所有加载的加载)。我发现它更可靠,然后tilesloaded / bounds_changed和使用 addListenerOnce 方法闭包中的代码被执行第一次空闲被触发,然后事件被分离。



另请参阅活动部分


I’m embedding Google Maps into my web site. Once Google Maps is loaded, I need to kick off a few JavaScript processes.

Is there a way to auto-detect when Google Maps has fully loaded, including tile downloads and all?

A tilesloaded() method exists that is supposed to accomplish exactly this task but it does not work.

解决方案

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

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.

See also the events section in the Google Maps Reference.

这篇关于如何检查Google地图是否已完全加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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