0

I am using Marker clusters in my application. I want to increase the grid size. I have customize the DefaultClusterRenderer class, but I didn't find any thing in it to increase the size.Please help me out how to increase it. following is the code of customized clusterRenderer

public class MyClusterRenderer extends DefaultClusterRenderer<MyItem> {

public MyClusterRenderer(Context context, GoogleMap map, ClusterManager clusterManager) {
    super(context, map, clusterManager);
}

@Override
protected boolean shouldRenderAsCluster(Cluster<MyItem> cluster) {
    //start clustering if at least 2 items overlap
    return cluster.getSize() > 4;
}

@Override
protected void onBeforeClusterItemRendered(MyItem item,MarkerOptions markerOptions){
    if(item.isRegister()==true)
    {
        BitmapDescriptor markerDescriptor = BitmapDescriptorFactory.defaultMarker(340);
        markerOptions.icon(markerDescriptor);

        //markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.x));
    }
    else if(item.isRegister()==false)
    {
        BitmapDescriptor markerDescriptor = BitmapDescriptorFactory.defaultMarker(60);
        markerOptions.icon(markerDescriptor).title("false");
    }
}

}
duncan
  • 31,401
  • 13
  • 78
  • 99
Ehsan Bhatti
  • 164
  • 2
  • 12
  • You might be able to use a combination of these answers http://stackoverflow.com/questions/23338772/maps-api-v3-clustering-at-different-zoom-levels/23341368#23341368, http://stackoverflow.com/questions/15700808/setting-max-zoom-level-in-google-maps-android-api-v2, and http://stackoverflow.com/questions/16331940/create-adaptive-grid-on-the-map-for-clusterization – Verma Sep 01 '15 at 20:49
  • @Verma Thanks, mentioned links may be helpful but I have solve this issue, I will post my answer soon. – Ehsan Bhatti Sep 01 '15 at 20:59

1 Answers1

0

A simple solution is use the NonHierarchicalDistanceBasedAlgorithm. Create a new calss and extends it with NonHierarchicalDistanceBasedAlgorithm, then override the method getClusters(double zoom). In this method you will be able to set the grid size, by changing the value of zoomSpecificSpan, In my i change the first value to 200.0D, and it works for me.

public Set<? extends Cluster<T>> getClusters(double zoom) {


    int discreteZoom = (int)zoom;
    double zoomSpecificSpan = 200.0D / Math.pow(2.0D, (double)discreteZoom) / 256.0D;
    HashSet visitedCandidates = new HashSet();
    HashSet results = new HashSet();
    HashMap distanceToCluster = new HashMap();
    HashMap itemToCluster = new HashMap();
    PointQuadTree var10 = this.mQuadTree;
Ehsan Bhatti
  • 164
  • 2
  • 12