Вопрос

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):

  • check if Marker.isCluster
  • loop over Marker.getMarkers
  • for every marker call GoogleMap.getMinZoomLevelNotClustered and remember the largest value from the loop
  • after loop call GoogleMap.animateCamera with some LatLng and the largest zoom value

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top