有人在谷歌地图 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/