Reputation: 5170
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
Upvotes: 2
Views: 4657
Reputation: 466
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);
Upvotes: 3
Reputation: 1006539
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.
Upvotes: 3