谷歌地图v3叠加层可以分组吗?

时间:2011-08-31 17:38:08

标签: arrays google-maps-api-3 google-maps-markers

查看Google Maps Javascript v3 API看起来如果我想将标记组合在一起并将其添加或删除为组,我需要根据下面的示例滚动自己的代码。

// Removes the overlays from the map, but keeps them in the array
function clearOverlays() {
  if (markersArray) {
    for (i in markersArray) {
      markersArray[i].setMap(null);
    }
  }
}

// Shows any overlays currently in the array
function showOverlays() {
  if (markersArray) {
    for (i in markersArray) {
      markersArray[i].setMap(map);
    }
  }
}

// Deletes all markers in the array by removing references to them
function deleteOverlays() {
  if (markersArray) {
    for (i in markersArray) {
      markersArray[i].setMap(null);
    }
    markersArray.length = 0;
  }
}

除了数组之外,是否有更优雅的解决方案来分组标记和infowindows?

1 个答案:

答案 0 :(得分:1)

根据您想要做的事情,MarkerClusterer可能会有所帮助:http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/docs/reference.html