1
LatLngBounds bounds = builder.build();

int width = getResources().getDisplayMetrics().widthPixels;
int height = getResources().getDisplayMetrics().heightPixels;
int padding = (int) (width * 0.10); // offset from edges of the map 10% of screen

CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, width, height, padding);

mMap.animateCamera(cu)

below attached image you can check.

Image link

2 Answers2

0

remove you height and width and set padding 0 and try it because google map provide max zoom and show according to the screen.

Amit pandey
  • 1,149
  • 1
  • 4
  • 15
0

you can calculate the bounds of all the markers you have:-

 val builder = LatLngBounds.Builder();
 for (builder in markers) {
 builder.include(marker.getPosition());
}
val bounds = builder.build();

Then obtain a movement object by using: CameraUpdateFactory:

val padding = 0; // offset from edges of the map in pixels
val cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);

Finally the map:

googleMap.moveCamera(cu);

if you want to animate:

googleMap.animateCamera(cu);

you can reduce zoom to focus latlng is middle of the map

rahul khurana
  • 188
  • 1
  • 9