【问题标题】:How to increase the grid size of Marker Cluster in android?如何在android中增加Marker Cluster的网格大小?
【发布时间】:2015-11-25 05:43:09
【问题描述】:

我在我的应用程序中使用标记集群。我想增加网格大小。我已经自定义了 DefaultClusterRenderer 类,但是我没有找到任何可以增加大小的东西。请帮我看看如何增加它。 下面是自定义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");
    }
}

}

【问题讨论】:

标签: google-maps google-maps-markers google-maps-android-api-2


【解决方案1】:

一个简单的解决方案是使用 NonHierarchicalDistanceBasedAlgorithm。创建一个新的 cals 并使用 NonHierarchicalDistanceBasedAlgorithm 对其进行扩展,然后覆盖方法 getClusters(double zoom)。在这种方法中,您将能够通过更改 zoomSpecificSpan 的值来设置网格大小,在我将第一个值更改为 200.0D,它适用于我。

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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-15
    • 1970-01-01
    • 2020-09-01
    • 1970-01-01
    • 2019-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多