How to set current location indicator behind map markers on MapBox (Z-Order)?

1k views Asked by At

Is it possible to place the MyLocation background drawable behind markers on MapBox Xamarin Android?

The current gps location indicator is default placed above all markers. Is there any way to configure this?

I've also tried to set my current location as a marker, but it looks like the z-order is based on the screen position, and I cant find a way to configure the z-order of Markers.

1

There are 1 answers

2
jgoldberger - MSFT On

UPDATE: Missed that this question was about MapBox. The below is just for the Google maps APIs. I suggest checking out MapBox's docs to see if they allow access to the ZIndex property of the underlying marker.

To set the Z-Order of Markers (where map is the GoogleMap instance):

 var markerFront = new MarkerOptions();
 markerFront.InvokeZIndex(1f); // Set the z-order
 markerFront.SetTitle("In Front");
 markerFront.SetPosition(new LatLng(lat, lon));

 var markerBack = new MarkerOptions();
 markerBack.InvokeZIndex(2f); // set the z-order
 markerBack.SetTitle("behind");
 markerBack.SetPosition(new LatLng(lat-0.0001, lon-0.0001));

 map.AddMarker(markerFront);
 map.AddMarker(markerBack);

And markerFront will be above markerBack. After thedse are set, though, they will be changed by the OS if you click on markerBack it will be moved to the front. I am not sure if the z-order can be changed after the marker is created, so if you need to keep the z-order when clicking on a marker, I think you would have to remove and re-add the marker with the z-order you want.

I could not find a way (after a very brief search) to change the z-order of the current location marker. Personally I would think you would always want the current location indicator in front anyway.