Search code examples
androidgoogle-mapsgoogle-polyline

Ordering layers in Android Google map


I have 2 types of objects on my map - GroundOverlays and Polylines.

My GroundOverlays (actually markers) are created from bitmaps. I need them to change size depending on the zoom level, that's why I went with GroundOverlays.

BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(createBitmap(getApplicationContext());
GroundOverlay m = mMap.addGroundOverlay(new GroundOverlayOptions().image(bitmapDescriptor).position(latLng, 100));

And then I have my PolyLines:

Polyline line = mMap.addPolyline(new PolylineOptions()
                    .add(new LatLng(gpsLat1, gpsLon1), new LatLng(gpsLat2, gpsLon2))
                    .width(12)
                    .color(myColor));

The issue I'm facing is, that the Polylines are drawn over my GroundOverlays. Is there a way to change the order of these 2 layers? Thanks.

EDIT: changing the order of drawing the elements doesn't help. If I draw the GroundOverlays first and Polylines next, or vice versa, polylines are always in front.


Solution

  • As Bhoomi, pointed out, there is an option to add z-index to Polylines and GroundOverlays. For example:

    line.setZIndex(10);
    ground_overlay.setZIndex(11);