Google Maps Android API Utility Library provides, among other things, classes for Manage bookmark groups .
By grouping the bookmarks, you can place a large number of bookmarks on a map without making the map difficult to read.
Using api is easy, there are 5 steps to implement:
1 - Implement a ClusterItem to represent each of the markers on the map.
public class Marcador implements ClusterItem {
private final LatLng mPosition;
public Marcador(double lat, double lng) {
mPosition = new LatLng(lat, lng);
}
@Override
public LatLng getPosition() {
return mPosition;
}
}
2 - Use a ClusterManager to group and manage bookmarks ( ClusterItem ).
private ClusterManager<MyItem> mClusterManager;
mClusterManager = new ClusterManager<Marcador>(this, getMap());
3 - Assign the ClusterManager to OnCameraChangeListener()
of the map.
getMap().setOnCameraChangeListener(mClusterManager);
4 - If you want to add specific functionality in response to a click on the marker, assign the ClusterManager to OnMarkerClickListener()
of the map.
getMap().setOnMarkerClickListener(mClusterManager);
5 - Add each of the ClusterItem tags to ClusterManager
double lat = 51.5145160;
double lng = -0.1270060;
Marcador marcador = new Marcador(lat, lng);
mClusterManager.addItem(marcador);
//Adicionar outros marcadores
......
......
Done, ClusterManager will manage your bookmarks, making sure the map is always easy to read.
To have Api available add the following dependency to the Gradle build file of the application:
dependencies {
compile 'com.google.maps.android:android-maps-utils:0.4+'
}
Font: Google Maps Android Marker Clustering Utility