使用Google Map Android API V2在两个位置之间路由

时间:2016-01-19 06:51:53

标签: android google-maps

我尝试使用本教程(http://wptrafficanalyzer.in/blog/driving-route-from-my-location-to-destination-in-google-maps-android-api-v2/)绘制两个位置。但它有效。问题是它不是缩放情节路径。

我想像这样enter image description here

但是给出结果如enter image description here

1)为什么这条路不能缩放?

2)如何缩放路径?

1 个答案:

答案 0 :(得分:3)

您可以使用Latlngbounds使用以下代码缩放路径

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

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

或者如果您想要为此设置动画

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