I used a library name mapviewballoon in my project mapviewballon .
when I set 20,30 or more pins the map on different locations it zooms to the last pin in the center, what I want is that the zoom level is such that it show up all pins in the map view.
how can I solve that, or calculate the right zoom, currently I given 14.
doing things as follow:
OverlayItem overlayItem = null;
GeoPoint point = null;
for (int i = 0; i < nearbyObjMapList.size(); i++) {
if (!nearbyObjMapList.get(i).latitude.equals("0") && !nearbyObjMapList.get(i).longitude.equals("0")) {
Latitude = Float.parseFloat(nearbyObjMapList.get(i).latitude);
Longitude = Float.parseFloat(nearbyObjMapList.get(i).longitude);
point = new GeoPoint((int)(Latitude*1E6),(int)(Longitude*1E6));
overlayItem = new OverlayItem(point, nearbyObjMapList.get(i).venue_name, "");
itemizedOverlay.addOverlay(overlayItem);
}
}
if (thisState == null) {
final MapController mc = mapView.getController();
mc.animateTo(point);
mc.setZoom(14);
} else {
// example restoring focused state of overlays
int focused;
focused = thisState.getInt("focused_1", -1);
if (focused >= 0) {
itemizedOverlay.setFocus(itemizedOverlay.getItem(focused));
}
focused = thisState.getInt("focused_2", -1);
if (focused >= 0) {
temizedOverlay2.setFocus(itemizedOverlay2.getItem(focused));
}
}
Don’t use setZoom() and it is always better to use zoomToSpan when you have many pins to be pointed. You add below code after your for loop, which works perfect for me.