PaNaVTEC PaNaVTEC - 1 year ago 196
Android Question

ClusterManager repaint markers of Google maps v2 utils

Hi Im making a server request and when I received the request from server, I'm executing on Ui Thread a ClusterManager.addItem() but this items are not painting in the map, only when I make a zoom update (+,-) are showing. Also, I tried to debug the renderer, but onBeforeClusterRendered / onBeforeClusterItemRendered are not called until I update the zoom in map.
Any ideas how to refresh map/clusterManager/markers?

MarkerManager markerManager = new MarkerManager(map);
clusterManager = new ClusterManager<TweetClusterItem>(getActivity(), map, markerManager);
clusterManager.setRenderer(new TweetClusterRenderer(getActivity(), map, clusterManager, defaultMarker));

UiSettings uiSettings = map.getUiSettings();


Answer Source

Seems that I found a workaround.

ClusterManager uses a renderer, in this case it inherits from DefaultClusterRenderer which uses a internal cache, a cache of markers that are added to map. You can access directly to the added markers on the map, I don't use the info window, so i add marker options.title() an ID for later find this marker, so:

protected void onBeforeClusterItemRendered(TweetClusterItem item, MarkerOptions markerOptions) {

     .... Blabla code....          
     .... Blabla code....


and when I want to reload the clusterItem I call this method:

  * Workarround to repaint markers
  * @param item item to repaint
  public void reloadMarker(TweetClusterItem item) {

        MarkerManager.Collection markerCollection = clusterManager.getMarkerCollection();
        Collection<Marker> markers = markerCollection.getMarkers();
        String strId = Long.toString(item.getTweet().getId());
        for (Marker m : markers) {
            if (strId.equals(m.getTitle())) {
                m.setIcon( ICON TO SET);


Maybe is a little hacky but it works and I din't found any other way to do this. If you found another better way, please share :)