Reputation: 4023
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.
Upvotes: 10
Views: 6579
Reputation: 11185
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;
}
Upvotes: 21