I haven\'t found an answer in my search, there are a few answers on SO but they didn\'t work for me.
I have 2 markers on the map and I am using LatLngBounds builder
Coming late but maybe someone has the same issue I had: I received bounds from a Place, not from a LatLngBounds.Builder:
I used Location.distanceBetween(...) to find out if the bounds were too small, and then use a minimum zoom level with the center of the bounds:
if (areBoundsTooSmall(bounds, 300)) {
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(bounds.getCenter(), 17));
} else {
mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 20));
}
The check method is:
private boolean areBoundsTooSmall(LatLngBounds bounds, int minDistanceInMeter) {
float[] result = new float[1];
Location.distanceBetween(bounds.southwest.latitude, bounds.southwest.longitude, bounds.northeast.latitude, bounds.northeast.longitude, result);
return result[0] < minDistanceInMeter;
}
I used min zoom level 17 and padding 20 for bounds that are too small, too small is definded here by min distance in meter 300. You can adjust the numbers as you need.