Android Google Maps SupportMapFragment Control Position and Padding

July 23, 2018
Reposition My location button

Use GoogleMap.setPadding to move map controls (my location, zoom control, compass, copyright, logo, etcs) to be fitted within the padded region.

Assuming I overlay a toolbar above SupportMapFragment and doesn’t want toolbar to obstruct google map’s control

googleMap.setPadding(0, toolbar.height, 0, 0)

The following Kotlin code can be used to move the location of My Location control specifically.

mapFragment.view?.findViewById<View>(Integer.parseInt("1"))?.also {
    (it.parent as View).findViewById<View>(Integer.parseInt("2")).also {
        it.updatePadding(top = toolbar.height)
    }
}

NOTE: updatePadding is part of android-ktx

This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.