我试图用服务器中的新数据更新我的地图,但我无法弄清楚如何从地图中删除旧项目(标记和集群 – 使用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).