Starting activity with clicking on google map marker infoWindow
android, google-maps, google-maps-android-api-2
Solution
I suggest using a HashMap or something similar. As you iterate over your list of objects and create markers for them, also add the Marker to a list, using the ID of the object as the key, and the marker as the value:
private HashMap<Integer, Marker> markerMap = new HashMap<Integer, Marker>();
...
for(MarkerObject obj : this.markerObjects)
{
//If the marker isn't already being displayed
if(!markerMap.containsKey(obj.getId()))
{
//Add the Marker to the Map and keep track of it
this.markerMap.put(obj.getId(), this.mMap.addMarker(getMarkerForObject(obj)));
}
}
Then you can use a OnInfoWindowClickListener to find the object id of the tapped marker in your Map and do something with the corresponding data, like open a new activity with details.
Problem
I have to start some activity with clicking on infoWindow (I can do this with `setOnInfoWindowClickListener()`), but this activity can be different, and I need something else. I should have a possibility to set an ID to every map marker. Can I pass custom ID to every Marker on map? Or how I can create button in `infoWindow` with this id (if I can do this, I can pass this id).