Overlapping Marker Spiderfier Marker Icon When There are Multiple Markers at Same Location

后端 未结 3 1596
春和景丽
春和景丽 2021-02-08 22:58

Google Maps doesn\'t provide a way to break apart multiple markers that are at the same location. This can occur with a people or businesses at a multiple residency location suc

3条回答
  •  深忆病人
    2021-02-08 23:47

    Some methods seems to be interesting like markersNearAnyOtherMarker but I cannot get it work. An interesting way could be to use spiderfy and unspiderfy events and change marker when it's fired

    overlappingMarkers = new OverlappingMarkerSpiderfier(map, overlapOptions);
    overlappingMarkers.addListener('spiderfy', function (markers) {
        markers.forEach(function (marker) {
            marker.setLabel('*');
            marker.setIcon(myNormalIcon);
        })
    })
    overlappingMarkers.addListener('unspiderfy', function (markers) {
        markers.forEach(function (marker) {
            marker.setLabel(''+markers.length);
            marker.setIcon(myOverlapIcon);
        })
    })
    

    Unfortunatly, the unspiderfy event isn't fired until we open then close the overlap marker. If I find a conclusion to this solution I will update this post.

提交回复
热议问题