How to check if Google Maps API is loaded?

前端 未结 10 2213
花落未央
花落未央 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 17:04

    If you are using jQuery, I have good news for you:

    if (typeof google === 'object' && typeof google.maps === 'object') {
         gmapInit();
    } else {
         $.getScript('https://maps.googleapis.com/maps/api/js?key='+gApiKey+'&language=en', function(){
             gmapInit();
         });
     }
    

    it's similar to answer-17702802

提交回复
热议问题