Android Google Maps SupportMapFragment Control Position and Padding

Jul 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

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.