I have to place different markers on a GoogleMap from the Google Maps Android v2 API. The problem is that multiple markers are set to the same position (lat/lng), so the user only sees the "newest" marker.
Is there a possibility (in the best case: a library) that clusters different markers from the same area (in relation to the zoomlevel)?
I've already read about the MarkerClusterer, but this is designed for the JavaScript API.
For others who are looking for implementing their own clustering code. Please check my clustering algo very fast and works amazingly good.
I looked at various libraries and found them so complex couldn't understand a word so I decided to make my own clustering algorithm. Here goes my code in java.
For who is having troubles with Clusterkraf (I can't make it work!) and for who can't use android-maps-extension cause it's shipped with a custom build of Play Services lib, I want to suggest this other library, that is tiny, well written and works out of the box:
After a whole morning spent trying using the other two libs, this one saved my day!
I'm a little late, but Clusterkraf is a great library, check it out:
https://github.com/twotoasters/clusterkraf
I haven't had a chance to try this out yet, but it looks very promising:
http://code.google.com/p/android-maps-extensions/
From this post
Here is another library with some pretty cool looking cluster animations:
https://github.com/twotoasters/clusterkraf
You need to follow these steps:
Android studio / Gradle:
Add a simple marker clusterer
Here is a summary of the steps required:
ClusterItem
to represent a marker on the map. The cluster item returns the position of the marker as a LatLng object.ClusterManager
to group the cluster items (markers) based on zoom level.OnCameraChangeListener()
to theClusterManager
, sinceClusterManager
implements the listener.OnMarkerClickListener()
to theClusterManager
, sinceClusterManager
implements the listener.ClusterManager
.Looking at the steps in more detail: To create our simple cluster of ten markers, first create a
MyItem
class that implementsClusterItem
.In your map activity, add the
ClusterManager
and feed it the cluster items. Note the type argument<MyItem>
, which declares the ClusterManager to be of typeMyItem
.Demo
https://www.youtube.com/watch?v=5ZnVraO1mT4
Github
If you need more information / completed project please visit: https://github.com/dimitardanailov/googlemapsclustermarkers
If you have more questions, please contact me.
Google has provided a utility to do this as part of their Google Maps Android API Utility Library:
https://developers.google.com/maps/documentation/android/utility/marker-clustering
with the source at:
https://github.com/googlemaps/android-maps-utils