其他分享
首页 > 其他分享> > android – 地图聚类 – 最大缩放标记仍然聚集

android – 地图聚类 – 最大缩放标记仍然聚集

作者:互联网

我正在使用android maps utils在google maps api v2上聚类标记.它工作正常,但当我添加2000个标记时,在最大缩放时它仍然是聚类的(标记仍然有数字):

这是我用标记填充地图的方法:

public void getRiverData(String state, String type) {
    URL = getResources().getString(R.string.base_url) + state + "/" + type
            + getResources().getString(R.string.end_url);
    SimpleXmlRequest<XMLData> simpleRequest = new SimpleXmlRequest<XMLData>(
            URL, XMLData.class, new Response.Listener<XMLData>() {

                @Override
                public void onResponse(XMLData response) {

                    // Initialize the manager with the context and the map.
                    // (Activity extends context, so we can pass 'this' in
                    // the constructor.)
                    mClusterManager = new ClusterManager<MarkerItem>(
                            getActivity(), map);

                    mClusterManager.setRenderer(new ClusterRenderer(
                            getActivity(), map, mClusterManager));

                    // response Object
                    waterItemsList = response.getNews();

                    for (News item : waterItemsList) {
                        if (item.getRiver_name() != null
                                && item.getRiver_name() != "") {

                            water_level_value = item.getWater_level_value();

                            if (water_level_value != null
                                    && !water_level_value.equals(0)
                                    && !water_level_value.equals("")) {

                                MarkerItem offsetItem = new MarkerItem(item);
                                mClusterManager.addItem(offsetItem);

                            }

                            map.setOnMarkerClickListener(mClusterManager);

                            map.setInfoWindowAdapter(new InfoWindowAdapter() {

                                @Override
                                public View getInfoWindow(Marker marker) {

                                    return null;
                                }

                                @Override
                                public View getInfoContents(Marker marker) {

                                    try {
                                        View v = getActivity()
                                                .getLayoutInflater()
                                                .inflate(
                                                        R.layout.marker_info,
                                                        null);
                                        TextView title = (TextView) v
                                                .findViewById(R.id.tvMarkerTitle);
                                        TextView info = (TextView) v
                                                .findViewById(R.id.tvMarkerInfo);

                                        title.setText(marker.getTitle()
                                                .toString());
                                        info.setText(marker.getSnippet()
                                                .toString());
                                        return v;
                                    } catch (Exception e) {
                                        // kliknięcie w cluster
                                        return null;

                                    }

                                }
                            });

                        }

                    }

                    map.setOnCameraChangeListener(mClusterManager);

                    map.setOnInfoWindowClickListener(mClusterManager);

                    mClusterManager.cluster();

                }

            }, new Response.ErrorListener() {
                @Override
                public void one rrorResponse(VolleyError error) {
                    // error Object
                    error.printStackTrace();
                }
            });

    AppController.getInstance().addToRequestQueue(simpleRequest);
}

谁能帮我?为什么不起作用?

解决方法:

您可以扩展DefaultClusterRenderer类并将最小标记设置为cluster.

public class InfoMarkerRenderer extends DefaultClusterRenderer<MyCustomMarker> {

public InfoMarkerRenderer(Context context, GoogleMap map, ClusterManager<MyCustomMarker> clusterManager) {
    super(context, map, clusterManager);
    //constructor
}

@Override
protected void onBeforeClusterItemRendered(final MyCustomMarker infomarker, MarkerOptions markerOptions) {
      // you can change marker options
}

@Override
protected boolean shouldRenderAsCluster(Cluster cluster) {
    return cluster.getSize() > 5; // if markers <=5 then not clustering
}
}

标签:android,google-maps,markerclusterer
来源: https://codeday.me/bug/20190713/1449674.html