Reputation: 713
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 ?
Upvotes: 3
Views: 1248
Reputation: 60
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:
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.
Upvotes: 4