I am making an application with a Google Maps on it, for Android. I have plenty of Markers on my screen and I am preparing customizable balloon for each marker when they are
There is a better option, and this is what google suggests:
Tag : An
Object
associated with the marker. For example, theObject
can contain data about what the marker represents. This is easier than storing a separateMap
. As another example, you can associate aString
ID corresponding to the ID from a data set. Google Maps Android API neither reads nor writes this property.
Source
So you can do something like this:
for (ListItem it: mList) {
Marker mk = mMap.addMarker(new MarkerOptions().position(it.getLatLng()).title(it.getName()).snippet(it.getAddress()));
mk.setTag(it.getID());
}
mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
Integer id = (Integer) marker.getTag();
return false;
}
});