I am trying to load a google map with some specific parmeters. I understand the problem is most likely that the initMap function needs to be declared globally. However, I h
Not a best way but it fixed my problem.
Call initMap() function manually as a fallback if ever the callback function wont work.
jQuery(document).ready(function($) {
initMap();
});
Hope this helps.
I copied your code but there are some syntax error. So i can't test. But your error is about initMap
(of course :)).
Delete all code and check initMap and your window.initMap.
function initMap() {alert("ok");}
Is google callback works?
async="false"
would work, try it!
In my case the function was async and it was crashing since the initmap was being called but it was not loaded at that point yet. So you can just write async="false" as mentioned before:
<script async="false" type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=<YOUR KEY>-39Fxo&libraries=places&callback=initMap"></script>
Anyone having a similar issue, initializing the map variable outside the initMap function worked for me
<script>
var map;
function initMap(){
//your code here
}
</script>
Found it... Though very late to the party...
If you downloaded the google maps js code from this link https://maps.googleapis.com/maps/api/js and then tried calling it using
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap">
</script>
There is bug in the development tools that the code gets modified.
Find the initMap
in the downloaded file and replace whole file with ""
Or replace with a fresh copy form the above link and then lock the file or mark it as ReadOnly to avoid the same in future.