Created
November 29, 2012 19:44
-
-
Save svenporto/4171366 to your computer and use it in GitHub Desktop.
Zoom map to see all GeoPoint items
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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