Skip to content

Instantly share code, notes, and snippets.

@svenporto
Created November 29, 2012 19:44
Show Gist options
  • Save svenporto/4171366 to your computer and use it in GitHub Desktop.
Save svenporto/4171366 to your computer and use it in GitHub Desktop.
Zoom map to see all GeoPoint items
private void zoomMapToSeeAllItems(MapView mapView, List<GeoPoint> items) {
int minLat = Integer.MAX_VALUE;
int maxLat = Integer.MIN_VALUE;
int minLon = Integer.MAX_VALUE;
int maxLon = Integer.MIN_VALUE;
double fitFactor = 1.5;
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);
}
mapView.getController().zoomToSpan((int) (Math.abs(maxLat - minLat) * fitFactor), (int)(Math.abs(maxLon - minLon) * fitFactor));
mapView.getController().animateTo(new GeoPoint((maxLat + minLat) / 2, (maxLon + minLon) / 2));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment