Google Maps e Markermanager genera un errore
-
19-09-2019 - |
Domanda
sto usando google map API insieme alla MarkerManager . Io caricare le librerie javascript 2 da jQuery.
Ecco la mia 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();
}
}
L'errore che ottengo in Firebug JavaScript debugger è:
GBounds non è definita [Rompere su questo errore] GBounds.prototype.containsPoint = function (punto) {\ nmarkerma ... 109.501.758 (linea 377)
me.getMapGridBounds_ non è una funzione [Rompere su questo errore] = me.shownBounds_ me.getMapGridBounds _ (); \ n markerma ... 109501758 (linea 106)
Questo errore si verifica anche se carico la libreria javascript staticamente.
Grazie,
Soluzione
Ci sono due problemi con il codice che vedo.
In primo luogo, non si utilizza il più recente verson di MarkerManager. Utilizzare la nuova qui:
http: // Gmaps -utility-library-dev.googlecode.com/svn/tags/markermanager/1.1/src/markermanager.js
In secondo luogo, la libreria MarkerManager richiede l'API GoogleMaps da caricare prima.
Inizia commutando l'ordine (non credo che questo funzionerà):
$.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');
Ma più probabilmente, avrete bisogno di qualcosa di simile a questo:
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();
}
});
}