How to check if Google Maps API (v3) is loaded?
I do not want to execute mapping scripts if the API did not load due to internet connectivity problems (web page is h
A simple if(google && google.maps) check didn't work for me; I still get an error when I try to access the API:
TypeError: google.maps.LatLng is not a constructor
In my case this is probably due to my mouse event handlers being triggered before the maps API has even finished downloading. In this case, to reliably check if maps is loaded, I create a "gmaps" alias and initialise it on dom ready (using JQuery):
var gmaps;
$(function () {
gmaps = google.maps;
});
then in my event handlers I can simply use:
if(gmaps) {
// do stuff with maps
}