gpt4 book ai didi

javascript - 如果标记大于 5,则 Google map 聚类

转载 作者:行者123 更新时间:2023-12-03 02:57:36 25 4
gpt4 key购买 nike

我正在尝试将集群添加到谷歌地图中,​​下面的代码很有用,但如果同一位置有超过 5 个标记,我需要添加集群。我该如何使用 MarkerClusterer 做到这一点?

   function map(data, baseLat, baseLng){
var markers = [];
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: new google.maps.LatLng(baseLat, baseLng),
mapTypeId: google.maps.MapTypeId.ROADMAP
});

var infowindow = new google.maps.InfoWindow();

$.each(data, function(i, val) {
var marker = new google.maps.Marker({
position: new google.maps.LatLng(val.property.lat, val.property.lng),
//map: map,
title: "Title"
});

markers.push(marker);

});

new MarkerClusterer(map, markers, {imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m'});
}

最佳答案

来自MarkerClustererPlus documentation

minimumClusterSize number

The minimum number of markers needed in a cluster before the markers are hidden and a cluster marker appears. The default value is 2.

将其设置为5:

new MarkerClusterer(map, markers, {minimumClusterSize: 5, imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m'});

关于javascript - 如果标记大于 5,则 Google map 聚类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47549978/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com