javascript - 为谷歌地图设置超时限制,如何测试?

标签 javascript jquery google-maps

有人在谷歌地图 API 上使用超时吗?我有一个从融合表中加载的谷歌地图。如果 map 没有在 x 秒内加载,我的客户希望我采用不同的解决方案。

我尝试使用 javascript 超时函数和 $(document).ready,但发现 jquery ready 在 map 呈现到屏幕之前就已启动。

综上所述...有没有人知道一种强制超时以测试某些可用解决方案的方法。

谢谢, 安迪

最佳答案

您可以使用 tilesloaded 事件吗?代码看起来像这样:

// set up the map and timeout
var map = new google.maps.Map(document.getElementById("map"), someOptions),
    timeoutSeconds = 4,
    usingMap = false;

function doAlternateStuff() {
    // do whatever the fallback requires
}

// set a timeout and store the reference
var timer = window.setTimeout(doAlternateStuff, timeoutSeconds * 1000);

// now listen for the tilesloaded event
google.maps.event.addListener(map, 'tilesloaded', function() {
    // cancel the timeout
    window.clearTimeout(timer);
    usingMap = true;
    // etc
});

关于javascript - 为谷歌地图设置超时限制,如何测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6768500/

相关文章:

javascript - 如何更改半正弦公式来计算固定点和​​用户位置之间的距离

javascript - ui-grid 突出显示某些特定行

android - 无法在我的 Android 应用程序中查看 Google map

javascript - 在脚本标签 block 之间调用 JavaScript 函数

javascript - jQuery 下拉菜单打开所有子菜单

Javascript递归settimeout

javascript - 在右上角显示一个小图像

jquery - 当用户将鼠标悬停在图像上时,如何获得图像的缩放效果?

javascript - 在谷歌地图 API 3 中切换位置

安卓|无法添加版本 15.0.1 的所有 Google 库