AndySousa
AndySousa

Reputation: 1122

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

Upvotes: 1

Views: 4673

Answers (1)

nrabinowitz
nrabinowitz

Reputation: 55678

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

Upvotes: 3

Related Questions