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 hosted locally).
if (google.maps) {...} will give you a reference error if google is undefined (i.e. if the API didn't load).
if (google.maps) {...}
Instead, use if (typeof google === 'object' && typeof google.maps === 'object') {...} to check if it loaded successfully.
if (typeof google === 'object' && typeof google.maps === 'object') {...}
1.4m articles
1.4m replys
5 comments
57.0k users