Zoom Map in Android

Zoom Map in Android
April 5, 2020 No Comments Android Development,Development Pushpendra Kumar

Hi Guys, Welcome to the new trick. Here you learn how to do zoom a map in android in android studio. And this trick I have explain you in the Kotlin programming language. Here I have took one location on which I am going to focus.

How to do Zoom map in android on click

First I will tell you, how you can find your target in android map on button lick event. Or how you can focus on any location or marker. And if you want to learn more about map in android then go through with this link.

private fun zoomMapInitial(latLang: LatLng) {
        try {
            val padding = 200
            val bc = LatLngBounds.Builder()

            bc.include(latLang);
            mMap!!.animateCamera(CameraUpdateFactory.newLatLngBounds(bc.build(), padding))
        } catch (e: Exception) {
            e.printStackTrace();
        }
    }

Above all the code which will zoom the any point of the marker. In addition Now below is the code for zooming two or more points on the map. 

private fun zoomMapInitial() {
        try {
            val padding = 200
            val bc = LatLngBounds.Builder()

            bc.include(LAT_LNG_ONE);
            bc.include(LAT_LNG_TWO)
            bc.include(LAT_LNG_THREE)
            bc.include(LAT_LNG_FOUR)
            /*And like the you can give as much as you want*/
            mMap!!.animateCamera(CameraUpdateFactory.newLatLngBounds(bc.build(), padding))
        } catch (e: Exception) {
            e.printStackTrace();
        }
    }

That’s great๐Ÿ˜Š๐Ÿ˜Š๐Ÿ˜Š๐Ÿ˜Š

And you can call this function as given below. 

button.setOnClickListener {
            var latLng = DEFAULT_LALANG;
            if (marker != null) {
                latLng = marker!!.position
            }
            zoomMapInitial(latLng)
        }

So dear friend this is completely a very sort trick for achieving your task. I hope it will help you.ย 

In conclusion, this the very sort trick for zooming an map in android with the help of Kotlin programming language. If you want any special topic or you need any additional help regarding this you can comment below or you can contact with me here!ย 

Tags
About The Author
Pushpendra Kumar I am passionate about mobile application development and professional developer at Colour Moon Technologies Pvt Ltd (www.thecolourmoon.com). This website I have made so that I can meet with new challenges and can share here.

Leave a reply

Your email address will not be published. Required fields are marked *