gpt4 book ai didi

javascript - initMap 不是函数 : Error

转载 作者:行者123 更新时间:2023-12-05 01:19:13 24 4
gpt4 key购买 nike

GoogleMap 在我的 Angular 项目(WebStorm IDE)中不可见!!

我试过使用回调函数!! GoogleMap 仍然不可见!! 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>

最佳答案

我曾经遇到过同样的问题。我通过从 src url 的末尾删除 '&callback=initMap' 来解决它。在你的情况下;

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

代替

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

关于javascript - initMap 不是函数 : Error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40588011/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com