To Google Maps Android API Utility Library offers, among others, classes for manage groups of bookmarks.
Grouping the markers, you can put a large number of markers on a map without making the map hard to read.
The use of api is easy, 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 - Attribute the Clustermanager at the OnCameraChangeListener()
of the map.
getMap().setOnCameraChangeListener(mClusterManager);
4 - If you want to add specific functionality in response to a bookmark click, assign the Clustermanager at the OnMarkerClickListener()
of the map.
getMap().setOnMarkerClickListener(mClusterManager);
5 - Add each of the markers(Clusteritem) at the Clustermanager
double lat = 51.5145160;
double lng = -0.1270060;
Marcador marcador = new Marcador(lat, lng);
mClusterManager.addItem(marcador);
//Adicionar outros marcadores
......
......
Done, the Clustermanager will manage the markers, ensuring that the map is always easy to read.
To have the Api available add the following dependency to Gradle build file of the application:
dependencies {
compile 'com.google.maps.android:android-maps-utils:0.4+'
}
Font: Google Maps Android Marker Clustering Utility
I don’t understand exactly how I should group Clustermanager can help me in this part?
– Maico Ribeiro
I will try to help but it is necessary for you to say, perhaps by asking another question, what is your specific question.
– ramaral
Okay, I have the map Fragment class, main Activity, Clusteritem class, it’s unclear if Clustermanager tbm is a class. if you could clarify a little or quote some examples I would be very grateful
– Maico Ribeiro
Yes it is a class (that belongs to the api), see in point 2 how it is instantiated. See here what to do to be able to use.
– ramaral