Kinda like this
int minLat = Integer.MAX_VALUE;
int maxLat = Integer.MIN_VALUE;
int minLon = Integer.MAX_VALUE;
int maxLon = Integer.MIN_VALUE;
for (GeoPoint item : items)
{
int lat = item.getLatitudeE6();
int lon = item.getLongitudeE6();
maxLat = Math.max(lat, maxLat);
minLat = Math.min(lat, minLat);
maxLon = Math.max(lon, maxLon);
minLon = Math.min(lon, minLon);
}
mapController.zoomToSpan(Math.abs(maxLat - minLat), Math.abs(maxLon - minLon));
mapController.animateTo(new GeoPoint( (maxLat + minLat)/2,
(maxLon + minLon)/2 ));
edit:
Ryan gave a nice suggestion : to put a padding so that some of the point don't lie on the edges (thanks Ryan!)
double fitFactor = 1.5;
mapController.zoomToSpan((int) (Math.abs(maxLat - minLat) * fitFactor), (int)(Math.abs(maxLon - minLon) * fitFactor));
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…