Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How set zoom level on google map dynamically in android?

Facing a problem to set dynamic zoom level in android google map.

something like doing In map application (system application of android).!

Searched City (zoom level for city)

Searched Area of city (zoom level for area)

I used below method of map

mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(START_POINT, 50)); mGoogleMap.animateCamera(CameraUpdateFactory.zoomTo(14.0f));

like image 368
Hitesh Dhamshaniya Avatar asked Feb 21 '26 13:02

Hitesh Dhamshaniya


1 Answers

Use following code:

mGoogleMap.animateCamera(CameraUpdateFactory.zoomTo(17),200, null);

Here 17 is zoom level you can change that.

Or try following code to cover all points

//Calculate the markers to get their position
LatLngBounds.Builder b = new LatLngBounds.Builder();
for (Marker m : markers) {
    b.include(m.getPosition());
}
LatLngBounds bounds = b.build();
//Change the padding as per needed
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 25,25,5);
mMap.animateCamera(cu);
like image 88
Yashdeep Patel Avatar answered Feb 24 '26 03:02

Yashdeep Patel