lyk
lyk

Reputation: 1598

Determining suitable zoom level based on a set of locations on Google Map Android API v2

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?

Upvotes: 1

Views: 1760

Answers (1)

Dan
Dan

Reputation: 1547

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);

Upvotes: 3

Related Questions