簡體   English   中英

Google Maps API-infobox.js和markerwithlabel.js-未定義Google

[英]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時-所以我將其修復,然后出現了其他問題。)

  1. 更改腳本包括:
<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>
  1. 添加(在DOM呈現后調用初始化函數的代碼):

    google.maps.event.addDomListener(window,'load',initialize);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM