Android Google地图Api在放大时不会取消群集

时间:2016-04-11 18:32:43

标签: java android google-maps google-maps-api-2 markerclusterer

我使用Custom Cluster RenderDefaultClusterRenderer<T>创建了Google Maps Api android maps utils markers。根据以下指南  https://github.com/googlemaps/android-maps-utils/blob/master/demo/src/com/google/maps/android/utils/demo/CustomMarkerClusteringDemoActivity.java

当我在同一区域中有更多markers时,它们会聚集到一个区域中。但是在缩放时不要分隔到 public PlaceRender(Context context, GoogleMap map, ClusterManager<MyCluster> clusterManager) { super(context, map, clusterManager); mIconGenerator = new IconGenerator(context); imageView = new ImageView(context); mClusterImageView = new ImageView(context); mIconGenerator.setContentView(imageView); this.context = context; this.map = map; this.myClusterManager = clusterManager; } @Override protected void onBeforeClusterItemRendered(MyCluster cluster, MarkerOptions markerOptions) { super.onBeforeClusterItemRendered(cluster, markerOptions); markerOptions.title(cluster.name).snippet(cluster.snippet); markerOptions.infoWindowAnchor(0.5f, 0.0f); } @Override protected void onBeforeClusterRendered(Cluster<MyCluster> cluster, MarkerOptions markerOptions) { super.onBeforeClusterRendered(cluster, markerOptions); } @Override protected boolean shouldRenderAsCluster(Cluster cluster) { // Always render clusters. return cluster.getSize() > 1; } @Override protected void onClusterRendered(Cluster<MyCluster> cluster, Marker marker){ super.onClusterRendered(cluster, marker); } @Override protected void onClusterItemRendered(MyCluster geo, Marker marker) { super.onClusterItemRendered(geo, marker); loadIconFromApi(geo, marker); } public void addItems(List<MyCluster> clusters, Context context, GoogleMap map) { myClusterManager = new ClusterManager<>(context, map); map.setOnMarkerClickListener(this); for (int i = 0; i < clusters.size(); i++) { myClusterManager.addItem(clusters.get(i)); myClusterManager.setRenderer(new PlaceRender(context, map, myClusterManager)); } myClusterManager.cluster(); } // private void loadIconFromApi(MyCluster geo, Marker marker) { PicassoMarker markers = new PicassoMarker(marker, mIconGenerator, imageView); geo.setPicassoMarker(markers); Picasso.with(context).load(geo.image).into(markers); } @Override public boolean onMarkerClick(Marker marker) { marker.showInfoWindow(); return true; } ,我可以看到

http://cs627121.vk.me/v627121202/51eb5/rY9f4p8ivos.jpg

以下是一些代码:

15x camera zoom

如果我使用zoom out,那么我可以看到每个标记,然后cluster,我的标记将不会合并到ComponentWillMount中。

我错过了什么?

2 个答案:

答案 0 :(得分:1)

由于您设置的条件,您的shouldRenderAsCluster()始终是群集。

cluster.getSize() > 1;

您可以在here

上查看类似的SO帖子

另外,请尝试查看此SO帖子。想知道您使用的是 PicassoMarker 库,这可能也会影响您的群集渲染。

答案 1 :(得分:0)

我需要添加此功能并在onCameraChange

中调用它
public void updateUI(List<MyCluster> clusters) {
        myClusterManager.clearItems();

        for (int i = 0; i < clusters.size(); i++) {
            myClusterManager.addItem(clusters.get(i));
         //   myClusterManager.setRenderer(new PlaceRender(context, map, myClusterManager));

    }
    myClusterManager.onCameraChange(map.getCameraPosition());
}