![](/img/trans.png)
[英]Google Maps API: markerwithlabel.js - Uncaught ReferenceError: google is not defined
[英]Google Maps API - infobox.js and markerwithlabel.js - google is not defined
在我的Google Maps Webapp中,我继续出现此错误:
infobox.js:126 Uncaught ReferenceError: google is not defined
它首先是在infobox.js内部触发的:
InfoBox.prototype = new google.maps.OverlayView();
我已经阅读了几篇关于这个确切主题的文章,包括:
这是我的<head>
部分:
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.3/jquery-ui.js"></script>
<script type="text/javascript" src="paypal/lightbox.js"></script>
<script async defer src="https://maps.googleapis.com/maps/api/js?v=3&key=AIzaSyD1vT***********1s6tNOgL2F44P8&callback=initialize&libraries=places"></script>
<script type="text/javascript" src="js/TreasureHunt.js"></script>
<script type="text/javascript" src="js/infobox.js"></script>
<script type="text/javascript" src="js/markerwithlabel.js"></script>
在TreasureHunt.js里面是我的initialize()函数:
function initialize() {
// set up basic/default world map, zoomed out, showing globe
var mapOptions = {
...
}
}
我尝试将js引用移到其他位置,但是没有任何效果。 Google强迫我使用&callback=initialize
方法,否则我的地图根本无法加载。 我曾经能够使用google.maps.event.addDomListener(window, 'load', initialize);
而不是异步,但不再起作用,地图不会加载。 我尝试将TreasureHunt.js放在地图API js文件之前和之后,但没有任何效果。 总是在infobox和markerwithlabel内,它认为google对象不存在。
我究竟做错了什么?
(注意:1年前,这一切一直很好,直到有一天,当我的本地地图js脚本停止工作并且Google现在需要从其服务器引用js时-所以我将其修复,然后出现了其他问题。)
<script async defer src="https://maps.googleapis.com/maps/api/js?v=3&key=AIzaSyD1vT***********1s6tNOgL2F44P8&callback=initialize&libraries=places"></script>
(删除async defer
和&callback=initialize
):
<script src="https://maps.googleapis.com/maps/api/js?v=3&key=AIzaSyD1vT***********1s6tNOgL2F44P8&libraries=places"></script>
添加(在DOM呈现后调用初始化函数的代码):
google.maps.event.addDomListener(window,'load',initialize);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.