Google 地图聚类器

Google Map Clusterer

我已经让聚类标记在某些标记上成功运行,但是,如果区域太拥挤,聚类似乎不会出现。我正在使用 Javascript API。

  this.map = new google.maps.Map(map, mapOptions);
  this.markers = data.map((location) => {
    if (location.location === null) return
    const marker = new google.maps.Marker({
      position: { lat: location.location.coordinates[0], lng: location.location.coordinates[1]},
      map: this.map
    });
    return marker
  });
  const markerCluster = new MarkerClusterer(this.map, this.markers, {
    imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m'
  });

我想要 post 图片,但我需要更多声誉。

我应该切换到热图还是这是集群库的已知限制?

编辑 似乎当我将标记的数量限制为 179 个时,它会将它们全部聚类,但是当我限制为 180 个时,第 180 个位于聚类之外

MarkerClusterer 库中没有 180 个标记的限制。当您查看 this example 时,您可以看到根据 gridSize.

聚集的 400 多个标记

你的 gridSize 不应该太小,所以更大的标记区域会聚集在一起,但你似乎使用了默认选项,这应该适用于你的示例。

您不必在创建标记时定义地图 - markerClusterer 会负责在地图上显示它们。

this.markers = [];
data.forEach(function(entry) {
    if (entry.location === null) return
    marker = new google.maps.Marker({
        position: { 
            lat: location.location.coordinates[0],
            lng: location.location.coordinates[1]
        }
    });
    markers.push(marker);
});
markerCluster = new MarkerClusterer(this.map, this.markers, {
    imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m'
});

另请检查 markerClusterer 的以下选项以根据您的需要对其进行配置:

  • gridSize: 簇的网格大小(以像素为单位)。
  • maxZoom: 标记可以成为集群一部分的最大缩放级别。
  • minimumClusterSize:一个标记的最小数量 在隐藏标记并显示计数之前进行聚类。