2017-08-25 4 views
1

AからB、Cまでの3つのポイントの間の方向を取得する方法現在のコードは2つのポイントから方向を取得しています。maps.googleapisから3つのポイント間の方向を取得する方法

private String getDirectionsUrl(LatLng origin, LatLng dest) { 

     // Origin of route 
     String str_origin = "origin=" + origin.latitude + "," + origin.longitude; 

     // Destination of route 
     String str_dest = "destination=" + dest.latitude + "," + dest.longitude; 

     // Sensor enabled 
     String sensor = "sensor=false"; 

     // Building the parameters to the web service 
     String parameters = str_origin + "&" + str_dest + "&" + sensor; 

     // Output format 
     String output = "json"; 

     // Building the url to the web service 
     String url = "https://maps.googleapis.com/maps/api/directions/" + output + "?" + parameters + "&key=" + getResources().getString(R.string.googleApiKey); 

     return url; 
    } 

答えて

1

私は方向APIには1つの起点と目的地しかないと思います。しかし、APIにはウェイポイントと呼ばれる機能があり、1つ以上の他のポイントを経由して旅行をルーティングすることができます。元の旅行がA -> Cだった場合、Bに停止を追加する場合は、ウェイポイントを追加して、旅行がBを確実に通過するようにすることができます。 documentationから

は、ここでは2つのウェイポイントとサンプルのURLです:

https://maps.googleapis.com/maps/api/directions/json?origin=Boston,MA& 
destination=Concord,MA&waypoints=Charlestown,MA|Lexington,MA&key=YOUR_API_KEY 
+0

OK、私は試してみましょう。 – byteC0de

関連する問題