markercluster y Google Maps v3 error “a es indefinido”
-
13-10-2019 - |
Pregunta
Estoy luchando tratando de agrupar 50 marcadores utilizando la versión 3 markerclusterer con Google Maps API v3.
He seguido el ejemplo sencillo encontrar en: http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/docs/examples.html para construir mi función sin embargo, cuando se carga el mapa me estoy haciendo el siguiente error en firebug:
a is undefined
Ba(H,function(a){if(!a)return l;return...){return new P(this.T.d,this.P.b,i)}; main.js (line 13)
Mi función es sólo hacer una simple llamada JSON para obtener el punto desde el servidor y luego construir la matriz de marcadores antes de añadirlos a la markerclusterer.
function addMarkerCluster(){
//get json data and create array of map markers and mark up the map using
//a map cluster
$.getJSON("feed/kml.php?action=json",
function(data){
var map;
var markers = [];
var latlng = new google.maps.LatLng(24.91654, 15.31326);
var myOptions = {
zoom: 3,
center: latlng,
mapTypeId: google.maps.MapTypeId.HYBRID
};
map = new google.maps.Map(document.getElementById("googlemap"), myOptions);
google.maps.event.addListener(map, "tilesloaded", function(){
attachFancyBox();
hideLoadDialog();
});
//loop through the data and add to the markers array the lat/lng of the centerpoints
//as google lat/lng objects.
$.each(data, function(i){
latlng = new google.maps.LatLng(this.lat, this.lng);
var marker = new google.maps.Marker(latlng);
markers.push(marker);
});
var markerCluster = new MarkerClusterer(map, markers);
});
}
Cualquier idea de por qué esto está causando los main.js Google mapa para fallar de esta manera? Si tan sólo añadir la MarkerClusterer sin el conjunto de marcadores del mapa presta sin errores.
Cuando agrego la matriz de marcadores de entonces los errores de mapas.
Gracias,
Grant
Solución
Fix fue simple que me perdería el hecho de que el Google Maps API v3 necesidades de tener un objeto que se le pasa. La solución fue cambiar
var marker = new google.maps.Marker(latlng)
to
var marker = new google.maps.Marker({'position' : latlng});