GoogleMaps does not load on page load

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:

<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBDucSpoWkWGH6n05GpjFLorktAzT1CuEc&callback=YOUR.NAMESPACE.initMap" async defer></script>

//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.

Leave a Comment