How to check if Google Maps API is loaded?

前端 未结 10 2135
花落未央
花落未央 2020-12-04 16:12

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

10条回答
  •  有刺的猬
    2020-12-04 16:49

    try

    (google && 'maps' in google)?true:false
    

    or

    if(google && 'maps' in google){
        //true
    }
    else{
        //false
    }
    

    since I had a problem with the following on mobile:

    if (typeof google === 'object' && typeof google.maps === 'object') {...}
    

提交回复
热议问题