Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

initMap is not a function: Error

GoogleMap is not visible in my angular Project (WebStorm IDE) !!

I have tried using callback function !! Still the GoogleMap is not visible !! I get this Error in Console


index.html

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

MapCtrl.js

 .controller('MapCtrl',function ($scope, $window) {

$window.initMap = function () {

    var map=new google.maps.Map(document.getElementById('map'), {
      center: {lat: -34.397, lng: 150.644},
      zoom: 8
    });

  }

});

Mymap.html

<div id="map" ng-controller="MapCtrl"></div>
like image 410
Vignesh Avatar asked Jul 11 '26 22:07

Vignesh


1 Answers

I had the same problem once. I solve it by removing '&callback=initMap' from the end of the src url. In your case;

<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAANu_sjcxDH04GZHg187EGg6csTeiX-jw"
     defer></script>

instead of

<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAANu_sjcxDH04GZHg187EGg6csTeiX-jw&callback=initMap"
     defer></script>
like image 55
BLACKRIGAN Avatar answered Jul 14 '26 12:07

BLACKRIGAN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!