Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Google Map Utils Clustering Distance

I'm using Android Google Map utils to enable clustering of my Markers. I'm using 10 Markers

When I press on a button, I call:

mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngBounds(getMarkerBoundingBox(), MAP_PADDING));

Eight of my markers are close to a given region so they are clustering and I can see a blue ball with the number eight on the center. The other two markers are far away from the other group but are really close to each other.

I'm now seeing a cluster with the eight markers and far away a single marker. Only if I zoom in in the area that single marker (that in fact are two) I can see both markers.

I want to show the cluster of the eight markers but a cluster of that two.

How can I decrease the distance that a cluster is created? At the limit, if markers are too close, I want clusters to be created at zoom level last but one.

I've tried to change MAX_DISTANCE_AT_ZOOM at NonHierarchicalDistanceBasedAlgorithm.java but with no success. Any ideas??

like image 323
Favolas Avatar asked Jul 04 '26 17:07

Favolas


1 Answers

Try to override shouldRenderAsCluster, so clustering starts from just 2 items:

When declaring the cluster manager:

    mClusterManager.setRenderer(new CustomRenderer<YOUR_TYPE>(getActivity(), googleMap, mClusterManager));

class CustomRenderer<T extends ClusterItem> extends DefaultClusterRenderer<T> {
    public CustomRenderer(Context context, GoogleMap map, ClusterManager<T> clusterManager) {
        super(context, map, clusterManager);
    }

    @Override
    protected boolean shouldRenderAsCluster(Cluster<T> cluster) {
        //start clustering if at least 2 items overlap
        return cluster.getSize() > 1;
    }
 ...
}
like image 184
MarionaDSR Avatar answered Jul 07 '26 05:07

MarionaDSR