I want to change the marker icon in google map on click . I can do it easily by overriding onMarkerClick
  @Override
  public boolean onMarkerClick(Marker marker) {
        marker.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.ic_selected_user_mark_icon));
        return true;
    }
But the problem is, lets say I have already clicked a marker which icon is already changed . When I click another marker it's icon also changed . What I actually want only clicked marker has a different icon . And the others will have same.
Save last clicked marker, and on second click restore it's icon to default
Marker lastClicked = null;
@Override
public boolean onMarkerClick(Marker marker) {
    if (lastClicked!=null)
        lastClicked.setIcon(<defaultIcon>);
    marker.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.ic_selected_user_mark_icon));
    lastClicked = marker;
    return true;
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With