Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set tag to Google Map's marker in Android?

I'm trying to set onInfoWindowClickListener for each marker that hit the related API according to the POJO id. That's what I found for setting onInfoWindowClick event.

googleMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {          @Override         public void onInfoWindowClick(Marker marker) {             // TODO Auto-generated method stub          }     }); 

But I need to set related pojo ids as tags to related markers before I do googleMap.addMarker(marker). But there is no such thing as marker.setTag(). How could I put my ID without setting tag?

like image 879
Zin Win Htet Avatar asked Feb 04 '16 09:02

Zin Win Htet


People also ask

How do I add a marker to Google Maps Android?

For adding a custom marker to Google Maps navigate to the app > res > drawable > Right-Click on it > New > Vector Assets and select the icon which we have to show on your Map. You can change the color according to our requirements. After creating this icon now we will move towards adding this marker to our Map.


2 Answers

Now You can do like this

Update your google play service version to

com.google.android.gms:play-services:9.4.0  Marker marker=mMap.addmarker(new MarkerOptions(LatLang)); // set object as tag marker.setTag(your object)  // to retrieve the marker marker.getTag();// Type cast to your object type; 
like image 68
BalaramNayak Avatar answered Sep 30 '22 15:09

BalaramNayak


I have one way. Just create HashMap with both your main Marker and another one with POJO Class and get back your POJO Class based on Particular Marker clicked on getInfoContents(.....)

like image 27
M D Avatar answered Sep 30 '22 15:09

M D