2010-01-10 63 views
1

我正在使用谷歌地圖API以及MarkerManager。我通過JQuery加載2個JavaScript庫。谷歌地圖和Markermanager拋出錯誤

這裏是我的javascript:

function initialize() { 
    $.getScript('http://gmaps-utility-library.googlecode.com/svn/trunk/markermanager/release/src/markermanager.js'); 
    $.getScript('http://maps.google.com/maps?file=api&v=2&async=2&callback=mapLoaded&sensor=true_or_false&key=ABC'); 

} 
function mapLoaded() { 
    if (GBrowserIsCompatible()) { 
     map = new GMap2(document.getElementById("map_canvas")); 
     map.setCenter(new GLatLng(18, -77.4), 13); 
     map.setUIToDefault(); 

     var mgr = new MarkerManager(map); 
     mgr.addMarkers(getWeatherMarkers(), 5); //gets some marker from another function 
     mgr.refresh(); 

    } 
} 

錯誤我的螢火獲取JavaScript調試器:

GBounds沒有定義 [此錯誤BREAK] GBounds.prototype.containsPoint =功能(點){\ nmarkerma ... 109501758(線377)

me.getMapGridBounds_不是函數 [打破這個錯誤] me.shownBounds_ = me.getMapGridBounds _(); \ n markerma ... 1 09501758(line 106)

如果靜態加載JavaScript庫,也會發生此錯誤。

謝謝,

回答

3

您看到的代碼有兩個問題。

首先,您沒有使用MarkerManager的最新版本。這裏使用的新的:

http://gmaps-utility-library-dev.googlecode.com/svn/tags/markermanager/1.1/src/markermanager.js

二,MarkerManager庫需要進行首次加載Google地圖API。

開始通過切換命令(我不認爲這將工作):

$.getScript('http://maps.google.com/maps?file=api&v=2&async=2&callback=mapLoaded&sensor=true_or_false&key=ABC'); 
$.getScript('http://gmaps-utility-library-dev.googlecode.com/svn/tags/markermanager/1.1/src/markermanager.js'); 

但更可能的是,你需要這樣的事情:

function initialize() { 
    $.getScript('http://maps.google.com/maps?file=api&v=2&async=2&callback=mapLoaded&sensor=true_or_false&key=ABC'); 
} 
function mapLoaded() { 
    $.getScript('http://gmaps-utility-library-dev.googlecode.com/svn/tags/markermanager/1.1/src/markermanager.js', function(){ 
     if (GBrowserIsCompatible()) { 
      map = new GMap2(document.getElementById("map_canvas")); 
      map.setCenter(new GLatLng(18, -77.4), 13); 
      map.setUIToDefault(); 

      var mgr = new MarkerManager(map); 
      mgr.addMarkers(getWeatherMarkers(), 5); //gets some marker from another function 
      mgr.refresh(); 
     }   
    }); 
} 
+0

谷歌移動MarkerManager到Github上。您會在此處找到新版本:https://raw.githubusercontent.com/googlemaps/v3-utility-library/master/markermanager/src/markermanager_packed.js – Tino 2016-05-12 09:41:02