问题
I made simple application where I get markers based on screen coordinates from the server. Problem is that markers doesn't appear on map immediately. User user must zoom in or zoom out only then marker is visible. Why is that? Is it possible to show marker as soon when marker data is downloaded from server? Or is it possible to somehow refresh map? I know that in previous version there was method map.invalidate()
that is basically what I need to have now. Unfortunately this method is not available now.
I will add code snippet how my markers is added
@Override
protected void onPostExecute(ArrayList<MarkerItemData> markerItemData) {
super.onPostExecute(markerItemData);
if(markerItemData != null) {
mClusterManager.addItems(markerItemData);
}
}
回答1:
It needs re-clustering again.
mClusterManager.addItems(markerItemData);
mClusterManager.cluster();
Because, when you add or remove an ClusterItem (MarkerItemData), it just performs the algorithm and calculates clusters. But does not render on map
Finally, ClusterManager listens onCameraIdle event(includes zoom events) and invokes cluster() method internally. This is the answer of user must zoom in or zoom out only then marker is visible.
回答2:
From the javadoc here, you need to recluster your markers after adding them to your ClusterManager
doing mClusterManager.cluster()
.
来源:https://stackoverflow.com/questions/41705216/android-maps-markers-show-on-map-only-after-zooming-change