Android Google Maps v2 - Add object to marker

Not really sure if this is the correct answer, but take a look at this blogpost I made about this problem:

Since Marker is final, it's this can easily be solved by linking the data with the Marker in a Map, for example HashMap<Marker, YourDataClass> or HashMap<Marker, String>

Here's a tutorial that explains all: http://bon-app-etit.blogspot.be/2012/12/add-informationobject-to-marker-in.html


As of Play Services v9.4.0, you can now set any object directly upon a marker!

To save the data:

Marker marker = getMap().addMarker(new MarkerOptions()
        .position(lat, lng)
        .title(spot.getName());

CustomObject myData = new CustomObject();
marker.setTag(myData);

Then to retreive your data:

CustomObject myRestoredData = (CustomObject)marker.getTag(myData);

For more infomration on marker data, here are the docs.