55

私は2つの位置の間の運転方向を取得しようとしています:

LatLng(12.917745600000000000,77.623788300000000000)
LatLng(12.842056800000000000,7.663096499999940000)

私が試したコード:

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

しかし、これは 2 点間に直線を引きます。

これらの2点間の運転ルートを取得する他の方法/方法はありますか?

4

3 に答える 3

150

AndroidでGoogle Maps Direction APIの最新ライブラリをリリースしました https://github.com/akexorcist/Android-GoogleDirectionLibrary

于 2013-02-24T16:36:11.773 に答える
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);
于 2013-04-23T04:10:52.990 に答える
3

その API の使用を支援することを目的とした次のプロジェクトを試すこともできます。ここにあります: https://github.com/MathiasSeguy-Android2EE/GDirectionsApiUtils

それがどのように機能するか、間違いなく単純です:

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);
    }
}
于 2013-10-08T13:06:30.327 に答える