Reputation: 6653
My map view contains many pinpoints.When ever the user takes that activity the map should be zoomed in such a level the correct 3 pints are visible.The map should not be zoomed more or less it should be exactly three.I know zoom level of the map can be varied from 0 to 21 through code.But is there any way to set the zoom level in such a way that exact 3 pins are visible in both the cases if the pins are far or near correct 3 should be visible?Is there any functionality in the API to set like that?
Upvotes: 0
Views: 695
Reputation: 1997
With points being all the geopoints you want to be visible on your map.
private void Zoom() {
int minLatitude = Integer.MAX_VALUE;
int maxLatitude = Integer.MIN_VALUE;
int minLongitude = Integer.MAX_VALUE;
int maxLongitude = Integer.MIN_VALUE;
for (GeoPoint p : points) {
int lati = p.getLatitudeE6();
int lon = p.getLongitudeE6();
maxLatitude = Math.max(lati, maxLatitude);
minLatitude = Math.min(lati, minLatitude);
maxLongitude = Math.max(lon, maxLongitude);
minLongitude = Math.min(lon, minLongitude);
}
mapController.zoomToSpan(Math.abs(maxLatitude - minLatitude),
Math.abs(maxLongitude - minLongitude));
mapController.animateTo(new GeoPoint((maxLatitude + minLatitude) / 2,
(maxLongitude + minLongitude) / 2));
}
Upvotes: 2