Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: window.initMap is not a function

I am following this tutorial, basically copy all the code

https://developers.google.com/maps/documentation/javascript/tutorial

but got an error saying that the initMap function is not a function. I am using angularjs in my project, could that be causing problems?

I copied the same code into plunker and it works just fine... What are the possible issues?

like image 858
user2901633 Avatar asked Sep 10 '15 08:09

user2901633


1 Answers

Actually the error is being generated by the initMap in the Google's api script

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

so basically when the Google Map API is loaded then the initMap function is executed. If you don't have an initMap function, then the initMap is not a function error is generated.

So basically what you have to do is one of the following options:

  1. to create an initMap function
  2. replace the callback function with one of your own that created for the same purpose but named it something else
  3. replace the &callback=angular.noop if you just want an empty function() (only if you use angular)
like image 162
DB.Null Avatar answered Sep 20 '22 08:09

DB.Null