GoogleMaps does not load on page load

后端 未结 6 1875
一个人的身影
一个人的身影 2020-11-29 09:21

I can\'t get my map running using the GoogleMaps API V3. The map does not load. I would expect the map to appear in the div with the id gisMap but in the Chrome

6条回答
  •  天涯浪人
    2020-11-29 10:12

    Make sure that initMap function is visible from the global scope or the parameter passed as callback to google maps.js is properly namespaced. In your case, the quickest solution will be replacing:

    function initMap(){
    //..
    }
    

    to:

    window.initMap = function(){
    //...
    }
    

    or namespace version:

    
    

    //Edit:

    I see that in your code snippet you use some async module loading (require.js?) and the code in which you create window.initMap function does not get executed unless you call the module that contains this declaration. So you have not fulfilled the first condition that I've mentioned - the initMap must be visible from the global scope before you call google maps.js.

提交回复
热议问题