Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 321
Rahul Gupta Avatar asked Oct 20 '14 08:10

Rahul Gupta


People also ask

How do I change the marker on Google Maps Android?

For adding a custom marker to Google Maps navigate to the app > res > drawable > Right-Click on it > New > Vector Assets and select the icon which we have to show on your Map. You can change the color according to our requirements. After creating this icon now we will move towards adding this marker to our Map.

How do I move a marker smoothly on Google Maps?

initialize() function creates a google Map with location Marker. transition() & moveMarker() are used to move location marker smoothly on Google Map.


1 Answers

Tried @Simo's answer, but it doesn't seem to work on my phone (maybe changed with Lollipop?) - when showInfoWindow() sees that there is nothing to display it seems to skip bringing the pin to the front. I was able to fix this by using the following layout:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="0dp"
              android:layout_height="0dp" >

    <!-- Need a " " so that showing this isn't a no-op -->
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text=" "/>
</FrameLayout>
like image 181
jt-gilkeson Avatar answered Oct 01 '22 08:10

jt-gilkeson