I\'m trying to port my application to the new Google Maps API v2, but i\'m having trouble when interacting with markers.
My context: I have a map showing buses and
I have run into this problem as well. My solution was:
private Map markerMap = new HashMap<>();
private GoogleMap mMap;
private void doMarkers(){
MarkerOptions opt = new MarkerOptions();
//Fill out opt from MyModel
Marker marker = mMap.addMarker(opt);
markerMap.put(marker, myModel);
}
and then in the OnMarkerClickListener callback, pull your model out of the HashMap using the clicked marker. There is also a method Marker.getId() which for some reason returns a string. I don't understand why you can't specify an int id when you make the marker, or why you can't access the marker object before you add it to the map.
UPDATE: After almost 4 years Google have added a method Marker.setTag(Object tag) to associate arbitrary data with a marker.