Javascript 设置谷歌地图的超时限制,以及如何测试它?

Javascript 设置谷歌地图的超时限制,以及如何测试它?,javascript,jquery,google-maps,Javascript,Jquery,Google Maps,有人在谷歌地图API上使用超时吗?我有一个从fusion表加载的google地图。如果地图没有在x秒内加载,我的客户希望我采用不同的解决方案 我尝试使用javascript超时函数和$(document.ready),但发现jQueryReady在映射被渲染到屏幕之前就启动了 尽管如此。。。是否有人知道强制超时以测试某些可用解决方案的方法 谢谢, Andy您可以使用tilesloadded事件吗?代码如下所示: // set up the map and timeout var map = ne

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

我尝试使用javascript超时函数和$(document.ready),但发现jQueryReady在映射被渲染到屏幕之前就启动了

尽管如此。。。是否有人知道强制超时以测试某些可用解决方案的方法

谢谢,
Andy

您可以使用
tilesloadded
事件吗?代码如下所示:

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

非常感谢。那正是我想要的。谢谢!我正在使用Angular 1,因此我应用了您的答案:
var timer=$timeout(doAlternateStuff,timeoutSeconds*1000);google.maps.event.addListener(映射'tilesload',函数(){$timeout.cancel(timer);})