【问题标题】:Can Google Map v3 Overlays be Grouped?Google Map v3 Overlays 可以分组吗?
【发布时间】:2011-11-07 19:54:41
【问题描述】:

查看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;
  }
}

除了数组之外,还有更优雅的对标记和信息窗口进行分组的解决方案吗?

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

    • 对于我的问题,最好的解决方案是保留标记数组,以便我可以在所有标记和方向之间切换“视图”。不过,这可能在以后有用。谢谢!
    猜你喜欢
    • 2011-03-23
    • 2011-05-12
    • 2012-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-30
    • 2023-03-30
    • 1970-01-01
    相关资源
    最近更新 更多