如何检测谷歌地图是否成功加载 [英] How to detect if google map loaded successfully

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

问题描述

我在我的网站上使用google-maps版本3.



我遇到了地图有时无法加载的问题,但它会显示为一个灰色的框,并且浏览器日志将会充满错误 - 不幸的是我现在无法获取日志,因为地图再次运行。



根据一些研究,问题是因为我使用的是实验版本

 < script src =https://maps.googleapis。 COM /地图/ API / JS v = 3.exp&安培; signed_in =假>< /脚本> 

有没有办法找出地图是否已成功载入或崩溃,所以我可以告诉用户很快就会回来?



PS我尝试了空闲事件,但即使地图崩溃,它也被调用。

听取tilesloaded事件。这是地图(成功)加载并且实际显示地图时触发的最后一个事件。



如果没有地图(例如,您没有设置宽度/显示高度),即使空闲,此事件也不会触发。



您可以使用地图事件示例,并从网络选项卡中限制您的连接以进行一些测试。 这里是宽度/高度没有为#map设置的例子。 / p>

I'm using google-maps version 3 in my website.

I ran through problems where the map sometimes does not load, but instead it will be shown as a grey box, and the browser log will be fulled with errors - unfortunately I can't get the log now because the map is working again.

According to some researches, the problem is because of the experimental version I'm using

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=false"></script>

Is There a way to find out if the map has been loaded successfully or crashed so I can tell the user to come back soon?

P.S. I tried the idle event, but it has been invoked even when the map crashed.

解决方案

Listen for the "tilesloaded" event instead. It's the last event to fire when a map (successfully) loads and you are actually showing a map.

If there's no map (e.g. you haven't set the width/height explicitly), this event won't fire even though idle does.

You can use the Map Events example and throttle your connection from within the Network tab to do some tests. Here's the same example with width/height not set for #map.

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

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