Hi again,
I've attempted to do a method my self, it doesn't work perfectly but it seems sufficient (maybe I should round the quotient up to have the real value):
private void adjustZoomToMarkers(ArrayList<GeoLocationFlag> flags) {
GeoPoint mapCenter = mapView.getMapCenter();
int lat = mapCenter.getLatitudeE6(), lng = mapCenter.getLongitudeE6();
int farestLat = 0, farestLng = 0;
for (GeoLocationFlag geoLocationFlag : flags) {
Log.d(LOG_TAG, "lat: " + geoLocationFlag.getLat());
int flagLatDistance = Math.abs(geoLocationFlag.getLat() - lat);
if (farestLat < flagLatDistance)
farestLat = flagLatDistance;
Log.d(LOG_TAG, "lng: " + geoLocationFlag.getLng());
int flagLngDistance = Math.abs(geoLocationFlag.getLng() - lng);
if (farestLng < flagLngDistance)
farestLng = flagLngDistance;
}
Log.d(LOG_TAG, "farest: " + farestLat + "," + farestLng);
Log.d(LOG_TAG, "spans: " + mapView.getLatitudeSpan() + "," + mapView.getLongitudeSpan());
// compute how many times this screen we are far on lat
float latQuotient = (float) farestLat / ((float) mapView.getLatitudeSpan() / 2);
// compute how many times this screen we are far on lng
float lngQuotient = (float) farestLng / ((float) mapView.getLongitudeSpan() / 2);
int zoom = 0;
if (latQuotient > 1 || lngQuotient > 1) {
// must zoom out
float qutient = Math.max((int) latQuotient, (int) lngQuotient);
while ((qutient / 2) > 1) {
qutient = qutient / 2;
zoom--;
}
} else {
float qutient = Math.max((int) (1 / (float) latQuotient), (int) (1 / (float) lngQuotient));
while ((qutient / 2) > 1) {
qutient = qutient / 2;
zoom++;
}
}
Log.d(LOG_TAG, "Zoom found " + zoom);
int zoomLevel = mapView.getZoomLevel();
mapController.setZoom(zoomLevel + zoom);
}
Best regards,
Zied Hamdi