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

前端 未结 3 1587
傲寒
傲寒 2021-02-03 22:12

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 settin

3条回答
  •  别跟我提以往
    2021-02-03 22:23

    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!

提交回复
热议问题