Android: Setting Zoom Level in Google Maps to include all Marker points
Yet another approach with Android Map API v2:
private void fixZoom() { List<LatLng> points = route.getPoints(); // route is instance of PolylineOptions LatLngBounds.Builder bc = new LatLngBounds.Builder(); for (LatLng item : points) { bc.include(item); } map.moveCamera(CameraUpdateFactory.newLatLngBounds(bc.build(), 50));}
I found out the answer myself, the Zoom level was correct. I need to add following code to display all points on screen.
objMapController.animateTo(new GeoPoint( (maxLatitude + minLatitude)/2, (maxLongitude + minLongitude)/2 ));
The center point was not propery aligned creating problem for me. This works.
Part of the problem could be that MIN_VALUE is still a positive number, but latitudes and longitudes can be negative numbers. Try using NEGATIVE_INFINITY instead of MIN_VALUE.