colonel32
colonel32

Reputation: 11

Bring map marker to front in Android Google Map

I have an Android app that displays multiple markers on a Google Map (using the Google Android APIs). When multiple markers overlap each other, I want the one a user clicks on to be brought to the front (think zIndex) but I haven't found a way to do this in Android.

Is there a simple way to force a selected marker to be brought to the front of the map? Or do I need to create a new overlay with just the single selected marker and place it on top of the overlay that has all the other markers?

Or do I need to reorder the overlays in my list and then force a redraw of all the markers?

Upvotes: 1

Views: 2157

Answers (1)

momo
momo

Reputation: 21343

zIndex in Google Map I think is simply done by the ordering of the overlays per the documentation.

To achieve your functionality, create a new single overlay containing only the clicked item. Basically you will just move from the original overlay to this one.

Steps:

  • Create empty overlay initially for the item that the users click. Let's call this one ClickedOverlay and put this one on top
  • As the user click a particular overlay, move from the original to ClickedOverlay
  • Using this method, you are not creating overlay with single item for every marker that the user click and you don't have to change the order of the overlay.

Upvotes: 2

Related Questions