Search code examples
androidgoogle-mapsgoogle-maps-markersgoogle-maps-api-2

Bring Google Map Markers to Front by Changing Z-Index in Android


I am creating a map based application where i show pings based on a latitude/longitude service

mMap.addMarker(new MarkerOptions()
    .position(mLatLng)
    .title("" + name)
    .snippet("" + pingDate)
    .icon(BitmapDescriptorFactory.fromBitmap(icon)));

According to google map v2 api, markers are drawn in a top to down approach, so my pings gets hidden if there are fully/partially above each other.

My question is, can i change the Z-Order axis or anything by which i can change the z position of a marker ?

Such that if i have two types of pings, i want to show one type of ping always on top irrespective of its coordinates


Solution

  • In latest release google map now have control over zIndex in Android. https://developers.google.com/maps/documentation/android-api/releases#june_27_2016

    You can use this now:

    mMap.addMarker(new MarkerOptions()
       .position(mLatLng)
       .title("" + name)
       .snippet("" + pingDate)
       .icon(BitmapDescriptorFactory.fromBitmap(icon))
       .zIndex(yourZIndex));
    

    From the documentation,

    The z-index specifies the stack order of this marker, relative to other markers on the map. A marker with a high z-index is drawn on top of markers with lower z-indexes. The default z-index value is 0.