Android Google Map Utils Clustering Distance

不羁岁月 提交于 2019-12-02 06:37:43

问题


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??


回答1:


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;
    }
 ...
}



回答2:


You can also use setMinClusterSize(1);

public MyIconRendered(Context context, GoogleMap map,
                      ClusterManager<AbstractMarker> clusterManager) {
    super(context, map, clusterManager);
    setMinClusterSize(1);
}


来源:https://stackoverflow.com/questions/27470137/android-google-map-utils-clustering-distance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!