How update markers on Map when using ClusterManager
I was concentrating the whole time on ClusterManager, so I forgot about GoogleMap, and specifically the method clear()
. I was able to solve the problem with this code:
mGoogleMap.clear();
mClusterManager.clearItems(); // calling just in case (may not be needed)
mClusterManager.addItems(LocationGetter.getReports());
There isn't any API to notify that a cluster item has been updated.
But you can use clusterManager.removeItem()
+ clusterManager.addItem()
to force an update to an item.
But you must be careful, as you normally want to update an item because it has changed some properties that affect rendering you need to use a custom ClusterRenderer
that supports this and overrides onClusterItemRendered()
and/or onClusterRendered()
. Using the onBefore variants wont work because they are only called once on marker creation.
You can look at this GitHub issue GitHub issue
According to ClusterManager
documentation, we can use mClusterManager.cluster();
This method Force a re-cluster. You may want to call this after adding new item(s).