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
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.