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

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;

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(.....)


Try to call setTag() method on map marker, not on the MarkerOptions object for.e.g.,

private void addMk(LatLng latLng, String title, String snips,String tagId) {
 MarkerOptions options = new MarkerOptions()
                .position(latLng)
                .title(title)
                .snippet(snips);
        
                 googleMap                 //Google googleMap object for map reference
                .addMarker(options)
                .setTag(tagId);

    }

googleMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {

        @Override
        public void onInfoWindowClick(Marker marker) {
            // TODO Auto-generated method stub
              
               String tagId= String.valueOf(marker.getTag());
                Log.d(TAG, "onInfoWindowClick: TAG_ID "+tagId);
        }
    }); 

Hope, this works!