Google Maps Javascript Api Not Loading Reliably
Solution 1:
You are getting this error:
Uncaught (in promise) "initMap is not a function"
Because your initMap
function is scoped within jquery's document.ready so you are asynchronously calling a global function that is never found as it's in fact not globally defined. The method only gets executed (and hence your map does load most times) because you call it again in your onload dom listener inside jquery's document.ready.
You can fix this in multiple ways, e.g. by placing this method in global scope, loading the Maps API synchronously, lazy loading it... Most recommended approach is to use a callback.
Check out related threads: Google maps API can't find a callback defined in $(document).readyMoving google maps api code to separate file + jquery
Hope this helps you.
Post a Comment for "Google Maps Javascript Api Not Loading Reliably"