0

In the android app that I am building, I have custom markers. The shape of these markers will be circular. Now on marker click I want to change to color of the marker.

Following are the 2 ways that come to my mind:

  1. Have 2 external images, one for unselected mode and one for selected mode. Set the unselected image as the default marker icon and on marker click change the marker icon to the selected mode.
  2. Define a circle drawable in XML. Set this drawable as the icon for the markers. On Marker click simply change the color of the drawable.

Please suggest what could be the best way to do this?

Gopal Singh Sirvi
  • 4,539
  • 5
  • 33
  • 55
  • 1
    Second approach is good one !! – Piyush Jun 03 '15 at 05:49
  • Either way sounds good. Also, I answered a question a while ago about changing the color of the currently selected marker, it might be of help to you: http://stackoverflow.com/questions/29740839/how-to-select-and-deselect-a-marker-in-google-maps-in-android – Daniel Nugent Jun 03 '15 at 06:45

1 Answers1

0

Ran into the same problem, here are some approaches

  1. use the same icon object, just change the color
  2. Set a different icon for this marker
  3. Prepare 2 different icon resource

For 1, there is no method in the google Map Marker class to support updating just the color (https://developers.google.com/android/reference/com/google/android/gms/maps/model/Marker), so 1 is out

For 2, we can tint the bitmap color and supply a new icon with marker.setIcon(icon) when a marker is click.

See how to tint here: https://stackoverflow.com/a/38249623/5777189

BabyishTank
  • 1,329
  • 3
  • 18
  • 39