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
Try implementing this way
/**
* Zooms a Route (given a List of LalLng) at the greatest possible zoom level.
*
* @param googleMap: instance of GoogleMap
* @param lstLatLngRoute: list of LatLng forming Route
*/
public void zoomRoute(GoogleMap googleMap, List lstLatLngRoute) {
if (googleMap == null || lstLatLngRoute == null || lstLatLngRoute.isEmpty()) return;
LatLngBounds.Builder boundsBuilder = new LatLngBounds.Builder();
for (LatLng latLngPoint : lstLatLngRoute)
boundsBuilder.include(latLngPoint);
int routePadding = 100;
LatLngBounds latLngBounds = boundsBuilder.build();
googleMap.moveCamera(CameraUpdateFactory.newLatLngBounds(latLngBounds, routePadding));
}
UPDATE
After looking at the image, there are layouts above map. So it would require you to set Variable Padding. You can do it as
googleMap.setPadding(left, top, right, bottom);
Note: While setting variable padding, you can initialize routePadding = 0
;
In your case, approximations are: left = right = 10
, bottom=100
, top=200
. Once set, you can calibrate'em as per your requirement.
Recommendation: You can calculate the height of those (top and bottom) layouts in pixels and then set padding accordingly.