Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

averageCenter on markerclusterer

I am using the google maps API to cluster markers.

For the moment the cluster center is set on the first marker added to it. Is there a way to put it in the average of all locations?

I am using the google map API V2 in android.

thanks,

EDIT: on this website they are talking about an attribute to set "averageCenter" http://component.kitchen/components/timeu/google-map-markerclusterer

is there an equivalent for android ?

like image 258
Nicolas Avatar asked Dec 11 '25 18:12

Nicolas


1 Answers

If you are using the Google Maps Android API utility library in your project, you can change the algorithm used for clustering.

The default algorithm used is the NonHierarchicalDistanceBasedAlgorithm (you can find the class file in library/src/com/google/maps/android/clustering/algo/).

Now you can:

  • either edit the source code of the class,
  • or create a new class extending NonHierarchicalDistanceBasedAlgorithm and overriding the getClusters(double) method. Then, use an instance of this class with your ClusterManager using setAlgorithm(Algorithm).

The changes that need to be made in order to calculate the center position of clusters can be found in this commit (I chose to edit the class directly). I did not measure the impact of these changes on the clustering calculation's speed though.


Edit: currently, a simple average is used to calculate the cluster's position, which is incorrect for latitude/longitude coordinates but is a bit faster.

You can find a better center calculation algorithm here: https://stackoverflow.com/a/14231286.

like image 97
tonymanou Avatar answered Dec 13 '25 07:12

tonymanou



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!