Set a timeout limit for Google Maps, and how to test it?
Is anyone out there using a timeout on with the google maps API? I have a google map which gets loaded from the fusion table. My client wants me to resort to a different solution if the maps doesn't load in x seconds.
I tried using a javascript timeout function and $(document).ready, but found that the jquery ready开发者_开发问答 was firing before the map was even rendered to the screen.
With all that said... does any one know a way to force a timeout to test some of the solutions that are available.
Thanks, Andy
Could you use the tilesloaded
event? The code would look something like this:
// 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
});
精彩评论