2011-06-26 19 views
0

私はGoogleの方向APIを使用し、jsonファイルとしてデータを受け取りました。私のurlはGoogleの方向API jsonファイルの解析

http://maps.googleapis.com/maps/api/directions/json?origin=Adelaide,SA&destination=Adelaide,SA&waypoints=optimize:true|Barossa+Valley,SA|Clare,SA|Connawarra,SA|McLaren+Vale,SA&sensor=false

のようなもので、私が最適化された使用:trueパラメータを。私が読んでいるところでは、それは私にソースから目的地までの最適な道をウェイポイントを通して与えてくれます。そして今、私はjsonファイルの構造を正確に知りません。私はjsonファイルの構造を調べますが、GoogleのAPIが私に与える経路の順序をどのように取ることができるのか分かりません。

+1

あなたは何か質問に回答してもらえません。これまであなたの古いものとそれを修正し、人々はあなたを助けるためにもっと喜んでなります – Eric

答えて

0

私もAndroidのは、Googleの方向性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); 
    } 
} 
0

呼び出しはあなたが従うべき最適なルートを提供します。どのルートが必要かを知るには、waypoint_orderの値を参照する必要があります。お電話の場合

、ウェイポイントの順序は次のとおりです。 「waypoint_order」:[3、2、0、1]

ので、最適な結果は、あなたが順番にウェイポイントを訪問する必要があるということでしょう:起源 - 3 - 2 - 0 - 1 - 行き先。あなたのケースでは

それは次のようになります。 アデレード、SA - マクラーレンベール、SA - Connawarra、SA - バロッサバレー、SA - クレア、SA - アデレード、SAお電話用

http://maps.googleapis.com/maps/api/directions/json?origin=Adelaide,SA&destination=Adelaide,SA&waypoints=optimize:true|Barossa+Valley,SA|Clare,SA|Connawarra,SA|McLaren+Vale,SA&sensor=false

関連する問題