The question is old but there's not a definitive answer, so I'll post mine:
I use this snippet everyday. THis will take care of handling the situation where the map view has just been created. Infact it can happend that you want to zoom to a boundingbox as a start behaiviour for the map. If you call this method before the view is displayed it will register a listener to execute the zoom as soon as the view is ready.
map
is my MapView
public void zoomToBounds(final BoundingBox box) {
if (map.getHeight() > 0) {
map.zoomToBoundingBox(box, true);
} else {
ViewTreeObserver vto = map.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
map.zoomToBoundingBox(box, true);
ViewTreeObserver vto2 = map.getViewTreeObserver();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
vto2.removeGlobalOnLayoutListener(this);
} else {
vto2.removeOnGlobalLayoutListener(this);
}
}
});
}
}
And here's how to get a boundingBox from a list of GeoPoints
public BoundingBox computeArea(ArrayList<GeoPoint> points) {
double nord = 0, sud = 0, ovest = 0, est = 0;
for (int i = 0; i < points.size(); i++) {
if (points.get(i) == null) continue;
double lat = points.get(i).getLatitude();
double lon = points.get(i).getLongitude();
if ((i == 0) || (lat > nord)) nord = lat;
if ((i == 0) || (lat < sud)) sud = lat;
if ((i == 0) || (lon < ovest)) ovest = lon;
if ((i == 0) || (lon > est)) est = lon;
}
return new BoundingBox(nord, est, sud, ovest);
}