我在Google地图标记群集中遇到问题。我正在使用api v3,但由于某些原因,我无法弄清楚,我无法应用标记聚类。我会感谢任何帮助和建议。
应用标记的功能与群集代码一起如下:
function setupOfficeMarkers() {
mgr.clearMarkers();
mgr.refresh();
allmarkers.length = 0;
document.getElementById('zomlevel').value = map.getZoom();
document.getElementById('boundsmap').value = map.getCenter();
// mapbound = map.getBounds();
mapbound=new google.maps.LatLngBounds();
for (var i in officeLayer) {
if (officeLayer.hasOwnProperty(i)) {
var layer = officeLayer[i];
var markers = [];
for (var j in layer["places"]) {
if (layer["places"].hasOwnProperty(j)) {
if(map.getZoom()>=layer["zoom"][0] && map.getZoom()<=layer["zoom"][1]){
//displaying home icon on places starts here
var place = layer["places"][j];
if(place["icon"]){
if(place["icon"][0]){
if(place["icon"][0] == 'own'){
}else{
var icon = getIcon(place["icon"]);
}
}else{
var icon = getIcon(place["icon"]);
}
}else{
var icon = getIcon(place["icon"]);
}
//displaying home icon on places ends here
var title = place["name"];
//alert(title);
var posn = new google.maps.LatLng(place["posn"][0], place["posn"][1]);
mapbound.extend(posn);
if(map.getBounds().contains(posn)){
if(place["icon"][0] == 'own'){
var imageUrl = place["icon"][1];
var markerImage = new google.maps.MarkerImage(imageUrl, new google.maps.Size(66, 65));
var marker = new google.maps.Marker({
position: posn,
draggable: false,
icon: markerImage
});
markers.push(50);
//alert(markers.length);
}else{
var marker = createMarker(posn, title, getIcon(place["icon"]));
}
mgr.addMarker(marker, layer["zoom"][0], layer["zoom"][1]);
attachSecretMessageAjax(marker, place["name"],map);
//attachSecretMessage(marker, '<h2>'+place["name"]+'</h2>',map);
}
//allmarkers.push(marker);
}
}
}
//mgr.addMarkers(markers, layer["zoom"][0], layer["zoom"][1]);
}alert(markers.length+"OUTSIDE");
var markerCluster = new MarkerClusterer(map, markers);
}
//alert(markers.length+"OUTSIDE");
mgr.refresh();
updateStatus(mgr.getMarkerCount(map.getZoom()));
}
答案 0 :(得分:0)
我不确定,但我认为你应该致电
markers.push(marker);
而不是
markers.push(50);
因为MarkerClusterer需要(1)map和(2)marker数组。我希望这有帮助。相反,您可以先调用Marker Clusterer构造,然后调用
markerCluster.addMarker(marker);
每个标记。