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).
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
if (google.maps) {...}will give you a reference error if google is undefined (i.e. if the API didn’t load).Instead, use
if (typeof google === 'object' && typeof google.maps === 'object') {...}to check if it loaded successfully.