Marker Clusterer for Google Maps on Android

Google Maps Android API v2 is a great library for Android developers to create maps application. It is very clear and easy to use. Creating map items and events are very easy. But, it has no facility for marker clustering. There are some samples on the net for clustering. Here is my solution about that.

I used Grid-based Clustering technique and i tried to port markerclusterer.js code that is from google-maps-utility-library-v3 project.

We have two classes for marker cluster operation.
    public class MarkerCluster
and
    public class MarkerClusterer
MarkerCluster class is the object that is container for clustered markers, and MarkerClusterer class has methods to create MarkerCluster objects.

How to use them?
  1. Add MarkerCluster, MarkerClusterer and MapUtils classes to your project. You can find them in the sample project. MapUtils class has mathematical calculations for our classes.
  2. Create your markers.
  3. Call createMarkerClusters method of MarkerClusterer class. It returns list of MarkerCluster object list.
  4. Loop on MarkerCluster object list and create your markers to add map.

   

You can find source code and sample usage on

Don't forget to set your "API_KEY" in manifest file to run sample project.

3 comments:

Anonymous said...

Hi,
nice Class ;)
Is there a method to uncluster a selected cluster by onclick?
Regards,
Bernd

Anonymous said...

The application close before start... I dont know why. I have my "API_KEY" but I dont know if I need to do something esle to use the google play services on my application. Any help will be appreciated.
Regards!
Marcelo.

wasim said...

Hey can you provide code. i can't find link for code in your post.
thanks.

Post a Comment