2

Hi I am using Google map in Android.where I am drawing a line between two GeoPoints.I need set the zoom level dynamically as the distance between two points increases or decreases.

Waiting for your reply

Altaf
  • 5,150
  • 10
  • 39
  • 55
  • i am not familiar google maps in android but in JavaScript version if you use LatLngBounds to contain your points, then you can use `map.fitBounds(bounds:LatLngBounds);` and it'll automatically adjust your view based on the LatLngBounds points. – KJYe.Name Apr 25 '11 at 19:33
  • Here a great answer by [Reno](http://stackoverflow.com/users/68805/reno): http://stackoverflow.com/a/5242149/1839565 – Defoncesko Jan 24 '13 at 17:33

2 Answers2

3

I've found similar solution. You can use CameraUpdateFactory.newLatLngBounds(LatLngBounds bounds, int padding)

Here is an example:

Builder boundsBuilder = LatLngBounds.builder();
ArrayList<LatLng> decodedPoints = (ArrayList<LatLng>) PolyUtil.decode(step);
for (LatLng point : decodedPoints) {
    boundsBuilder.include(point);
}
LatLngBounds bounds = boundsBuilder.build();
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(bounds, 10);
map.moveCamera(cameraUpdate);
dahec
  • 466
  • 5
  • 10
3

Use zoomToSpan() on MapController. Compute the span based on the distances between your points. If your points are not centered, either take that into account (by increasing the desired span) or recenter the map.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491