使用Google Maps API v2获取行车路线

Anu*_*ool 52 java android google-maps directions google-maps-android-api-2

我想在两个位置之间找到行车方向:

LatLng(12.917745600000000000,77.623788300000000000)
LatLng(12.842056800000000000,7.663096499999940000)
Run Code Online (Sandbox Code Playgroud)

我试过的代码:

Polyline line = mMap.addPolyline(new PolylineOptions().
    add(new LatLng(12.917745600000000000,77.623788300000000000),
    new LatLng(12.842056800000000000,7.663096499999940000))
       .width(5).color(Color.RED));
Run Code Online (Sandbox Code Playgroud)

但这在两点之间划了一条直线.

有没有其他方法/方法来获得这两点之间的行车路线.

Ake*_*ist 145

我刚刚在Android上发布了我最新的Google Maps Direction API库 https://github.com/akexorcist/Android-GoogleDirectionLibrary

  • @Akexorcist我按照提供的代码获取空指针异常错误消息.你有什么主意吗? (3认同)
  • 我最新的Google方向API代码https://github.com/akexorcist/Android-GoogleDirectionAndPlaceLibrary (2认同)
  • @Akexorcist嗨,我在nl1 = doc.getElementsByTagName("step")得到一个NullPointerException; 在你的GMapV2Direction课程中,你知道为什么吗? (2认同)

Bas*_*rif 17

这是我正在使用的,

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);
Run Code Online (Sandbox Code Playgroud)

  • 这是一个Web实现我不认为这是他想要的. (2认同)