[英]Get driving directions using Google Maps API v2
I am trying to get the driving direction between the two positions:我正在尝试获取两个位置之间的行驶方向:
LatLng(12.917745600000000000,77.623788300000000000)
LatLng(12.842056800000000000,7.663096499999940000)
The code which i have tried:我尝试过的代码:
Polyline line = mMap.addPolyline(new PolylineOptions().
add(new LatLng(12.917745600000000000,77.623788300000000000),
new LatLng(12.842056800000000000,7.663096499999940000))
.width(5).color(Color.RED));
But this draws a straight line between the two points.但这在两点之间画了一条直线。
Is there any other method/way to get the driving directions between these two points.是否有任何其他方法/方式来获取这两点之间的行车路线。
我刚刚在Android上发布了我最新的Google Maps Direction API库https://github.com/akexorcist/Android-GoogleDirectionLibrary
This is what I am using, 这是我正在使用的,
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr="+latitude_cur+","+longitude_cur+"&daddr="+latitude+","+longitude));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addCategory(Intent.CATEGORY_LAUNCHER );
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
You can also try the following project that aims to help use that api. 您还可以尝试以下旨在帮助使用该API的项目。 It's here: https://github.com/MathiasSeguy-Android2EE/GDirectionsApiUtils 它在这里: https : //github.com/MathiasSeguy-Android2EE/GDirectionsApiUtils
How it works, definitly simply: 它是如何工作的,绝对简单:
public class MainActivity extends ActionBarActivity implements DCACallBack{
/**
* Get the Google Direction between mDevice location and the touched location using the Walk
* @param point
*/
private void getDirections(LatLng point) {
GDirectionsApiUtils.getDirection(this, mDeviceLatlong, point, GDirectionsApiUtils.MODE_WALKING);
}
/*
* The callback
* When the direction is built from the google server and parsed, this method is called and give you the expected direction
*/
@Override
public void onDirectionLoaded(List<GDirection> directions) {
// Display the direction or use the DirectionsApiUtils
for(GDirection direction:directions) {
Log.e("MainActivity", "onDirectionLoaded : Draw GDirections Called with path " + directions);
GDirectionsApiUtils.drawGDirection(direction, mMap);
}
}
I've found this -我发现了这个-
val polyline1 = map?.addPolyline(
PolylineOptions().clickable(true)
.add(LatLng(23.8103, 90.4125), LatLng(4.0383, 21.7587))
.geodesic(true)
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.