gpt4 book ai didi

google-maps - 同一位置有多个标记 - MarkerClusterer

转载 作者:行者123 更新时间:2023-12-03 04:34:54 25 4
gpt4 key购买 nike

我正在使用 MarkerClusterer。当我在同一位置有两个或多个标记时,API 仅显示 1 个标记 - 最上面的一个。但不知何故,我想显示所有标记,因为每个标记都会打开不同的弹出窗口。我搜索过几个解决方案,但似乎没有一个有效有人有类似的问题并请分享解决方案吗?

最佳答案

终于可以用了。这适用于所有尚未找到解决方案的人。下面的代码向同一位置的标记添加偏移量:

在您的 createMarker 函数中添加以下代码:

//get array of markers currently in cluster
var allMarkers = namespace.mapParams.mapMarkersArray;

//final position for marker, could be updated if another marker already exists in same position
var finalLatLng = latlng;

//check to see if any of the existing markers match the latlng of the new marker
if (allMarkers.length != 0) {
for (i=0; i < allMarkers.length; i++) {
var existingMarker = allMarkers[i];
var pos = existingMarker.getPosition();

//if a marker already exists in the same position as this marker
if (latlng.equals(pos)) {
//update the position of the coincident marker by applying a small multipler to its coordinates
var newLat = latlng.lat() + (Math.random() -.5) / 1500;// * (Math.random() * (max - min) + min);
var newLng = latlng.lng() + (Math.random() -.5) / 1500;// * (Math.random() * (max - min) + min);
finalLatLng = new google.maps.LatLng(newLat,newLng);
}
}
}

Refer this

现在使用新位置值更新每个标记的 google.maps.Marker 对象 - finalLatLng

var marker = new google.maps.Marker({
map: msf_namespace.mapParams.resultmap,
position: finalLatLng,
title: name,
icon: markericon
});

//add each generated marker to mapMarkersArray
namespace.mapParams.mapMarkersArray.push(marker);

关于google-maps - 同一位置有多个标记 - MarkerClusterer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20490654/

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