Sometimes when markers are really close to each other, it requires many clicks to zoom enough so that the cluster unfolds and shows all the markers individually.
How can I make it so that one click on a cluster always zooms in and unfolds it correctly?
If you wanted to zoom to show all the markers from a single cluster, you could end up showing only some of them. If that's ok with you, here are the steps (e.g. in onMarkerClick
):
Marker.isCluster
Marker.getMarkers
GoogleMap.getMinZoomLevelNotClustered
and remember the largest value from the loopGoogleMap.animateCamera
with some LatLng
and the largest zoom valueThe problem here is to decide what LatLng
to choose. If you choose the one from cluster marker, you could even end up not showing any marker after zoom.
Alternatively you may want to zoom to LatLngBounds
created from all the markers in the cluster. This will not make it to show all markers, but for sure you would end up with all markers still hidden somewhere on the screen.