I have a list of random latitude and longitude points and I am drawing a route between them. My question is how to bound this route within google map I made below utili
You need to include all the points that form the polyline into your mapBounds
object.
Also, you are updating the camera using animateCamera
and then you are moving it using moveCamera
. This second camera update overrides the first one. Just remove the line
googleMap.moveCamera(CameraUpdateFactory.zoomOut());
This line is also innecesary (you don't need to move and animate the camera, just one of them):
googleMap.moveCamera(CameraUpdateFactory.newLatLngBounds(mapBounds.build(), 10));
If you need to zoom out a bit your map you can play with the padding parameter of the CameraUpdateFactory.newLatLngBounds
method.