2

I am trying to get a reference to my markers (without using getMarkerCollections) on my clustered Google Map but I am having trouble finding where to override this function.

I have made a typical ClusterManager that works fine, but I can't override the function anywhere in that class.

Do I need to make a custom class for this and how would I do that?

Mike Laren
  • 8,028
  • 17
  • 51
  • 70
Jacob Platin
  • 319
  • 3
  • 11
  • What exactly are you trying to do? Take a look at this answer just in case it helps: http://stackoverflow.com/questions/30958224/android-maps-utils-clustering-show-infowindow/30959578#30959578 – Daniel Nugent Jul 25 '15 at 17:58
  • @DanielNugent thanks for the quick answer, but I am trying to get a reference to all the markers on my map and then put them in a list. You commented on my other question, but I think this is the better question. – Jacob Platin Jul 25 '15 at 18:02

1 Answers1

1

To answer your question directly, you will need to create a custom class that extends DefaultClusterRenderer, and then override the onClusterItemRendered() method:

public class MyRenderer extends DefaultClusterRenderer<MyItem> {

    public MyRenderer(Context context, GoogleMap map, ClusterManager<MyItem> clusterManager) {
        super(context, map, clusterManager);
    }

    @Override
    protected void onClusterItemRendered(MyItem clusterItem,
                                         Marker marker) {
        super.onClusterItemRendered(clusterItem, marker);

        //other stuff......
    }
}

Then, you would call the setRenderer() method and give it a new instance of your MyRenderer object:

mClusterManager.setRenderer(new MyRenderer(this, mMap, mClusterManager));
Daniel Nugent
  • 43,104
  • 15
  • 109
  • 137
  • I just have a quick relevant question that I wanted to ask you: is there any way to get a reference to a clustered marker (as in a marker that is clustered, not the cluster circle itself)? – Jacob Platin Jul 26 '15 at 13:40
  • @jacob it's probably not necessary to do that. Can you explain exactly what functionally you need that is not included in the answer I linked to? I can help guide you in the right direction. – Daniel Nugent Jul 26 '15 at 14:51