Tharindu Dhanushka
Tharindu Dhanushka

Reputation: 337

Route between two locations with in Google Map Android API V2

I try to plot two location using this tutorial(http://wptrafficanalyzer.in/blog/driving-route-from-my-location-to-destination-in-google-maps-android-api-v2/) . But it work . Problem is it not zoom plot path.

I want to out put like this enter image description here

But give the result like thisenter image description here

1) why this path not zoom ?

2) how to zoom the path?

Upvotes: 1

Views: 4431

Answers (1)

Punit Sharma
Punit Sharma

Reputation: 2947

You can use Latlngbounds to zoom your path using following code

 Builder boundsBuilder = new LatLngBounds.Builder();
 boundsBuilder.include(currentLocationLatLng);
 boundsBuilder.include(targetLocationLatLng);

 LatLngBounds bounds = boundsBuilder.build();
 googleMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 3));

or if you want to animate this too

CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
googleMap.moveCamera(cu);
googleMap.animateCamera(cu);

Upvotes: 3

Related Questions