Gri*_*ish 13 google-maps google-maps-api-3 markerclusterer
我正在使用MarkerClusterer.当我在完全相同的位置上有两个或更多标记时,API仅显示1个标记 - 最上面的一个.但不知何故,我想显示所有标记,因为每个标记将打开不同的弹出窗口.我搜索了几个解决方案,但没有一个似乎工作任何人都有类似的问题,并会分享一个解决方案?
Gri*_*ish 28
终于搞定了.这适用于所有尚未找到解决方案的人.下面的代码为相同位置的标记添加了偏移量:
在您的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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
24154 次 |
| 最近记录: |