Search code examples
androidmarkergoogle-maps-android-api-2z-order

Google Maps v2 Marker zOrdering - Set to top


I know there are a few threads around on this topic but i havent yet found a good enough solution.

I NEED to place a marker over the top of all other markers. How do i do this?

I have tried adding this marker before and after all other markers, however the ordering seems to be from bottom (front) to top (back) on the map view. This is not acceptable as I want to center on a marker which is in front of all markers.

I know that Polygons can be zOrdered but I would MUCH prefer a nicely styled graphic!

In-fact you can't order a Polygon over a marker!

"The order in which this polygon is drawn with respect to other overlays, including Polylines, GroundOverlays and TileOverlays, but not Markers. An overlay with a larger z-index is drawn over overlays with smaller z-indices. The order of overlays with the same z-index value is arbitrary. The default is 0." - https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/model/Polygon

Does anyone have any ideas on this?


Solution

  • Whilst not the perfect solution! I have figured out how to show a selected (tapped) marker over all other markers by consuming the onMarkerClick event. Returning TRUE will consume this event, so we have to do the showInfoWindow and zoom to center

        @Override
        public boolean onMarkerClick(Marker marker) {
    
           //Manually open the window
           marker.showInfoWindow();
    
           //Animate to center
           sMapFrag_v2.getMap().animateCamera(CameraUpdateFactory.newLatLng(marker.getPosition());
    
           //Consume the method
           return true;
        }