Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set id for an google map marker to identify which one is selected?

how to find which marker is selected in the list of markers in google map from onMarkerClicked(Marker marker) callback.

like image 324
Manokar Avatar asked Nov 21 '22 18:11

Manokar


1 Answers

The recommended way to do this is to have a Hash with marker ID and your custom data. The Marker object might change if the activity is killed and restored but the ID will remain the same. You map would look like:

HashMap<String, MyObject> markersAndObjects = new HashMap<String, MyObject>();

Marker objects have a getId() method to get the ID. Hope it helps.

like image 135
Kristo Avatar answered Nov 23 '22 09:11

Kristo