android – 使用ClusterManager时如何在Map上更新标记

前端之家收集整理的这篇文章主要介绍了android – 使用ClusterManager时如何在Map上更新标记前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图用服务器中的新数据更新我的地图,但我无法弄清楚如何从地图中删除旧项目(标记和集群 – 使用ClusterManager)( – 在我看来,我只能在ClusterManager中添加.

我有BroadcastReceiver,当有新数据时它会获得意图.我正在尝试这样的事情:(但它在“… getMarkers().clear();”上给了我UnsupportedOperationException.“

private BroadcastReceiver myRefrestMapBroadcastReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context,Intent intent) {
        Log.d(TAG,"onReceive");
        mClusterManager.clearItems();
        mClusterManager.getMarkerCollection().getMarkers().clear();
        mClusterManager.getClusterMarkerCollection().getMarkers().clear();
        mClusterManager.addItems(LocationGetter.getReports());
    }
};

添加的数据仅用于此功能.

java.util.Collection<Marker> userCollection = mClusterManager.getMarkerCollection().getMarkers();
            ArrayList<Marker> userList = new ArrayList<Marker>(userCollection);
            // now is userList empty
            for(Marker marker: userList){
                marker.remove();
            }

            java.util.Collection<Marker> userCollection2 = mClusterManager.getClusterMarkerCollection().getMarkers();
            ArrayList<Marker> userList2 = new ArrayList<Marker>(userCollection2);
            // now is userList2 empty
            for(Marker marker: userList2){
                marker.remove();
            }

            mClusterManager.addItems(LocationGetter.getReports());

解决方法

根据ClusterManager documentation,我们可以使用mClusterManager.cluster();

This method Force a re-cluster. You may want to call this after adding new item(s).

猜你在找的Android相关文章