1

I'm trying to find if there's an algorithm/method out there that can help determine a suitable zoom level for initial display.

For example, given a set of locations Point A,B,C,D and E, how can I determine the correct zoom level that will display all locations on the screen?

lyk
  • 1,578
  • 5
  • 25
  • 49

1 Answers1

3
LatLngBounds.Builder builder = new LatLngBounds.Builder();
for (Location loc : allLocations) {

    LatLng position = new LatLng(loc.getLatitude(), loc.getLongitude());
    builder.include(position);

}

CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(builder.build(), someMarginValue);
map.moveCamera(cu);
Dan
  • 1,539
  • 12
  • 23
  • Thanks for this! However I get this error: 01-27 23:41:39.820: E/AndroidRuntime(20092): java.lang.IllegalStateException: Map size should not be 0. Most likely, layout has not yet occured for the map view. At the line map.moveCamera(cu). what does this mean? – lyk Jan 27 '13 at 15:45
  • Never mind I found the answer here... http://stackoverflow.com/questions/13692579/movecamera-with-cameraupdatefactory-newlatlngbounds-crashes Thanks alot! – lyk Jan 27 '13 at 15:52