2016-08-22 149 views
0

我從地圖API兩點之間的響應和分析,並在地圖上繪製折線,但問題是該直線籠絡建設谷歌地圖方向Api返回錯誤的方向?

代碼繪製折線:

JSONArray steps = response.getJSONObject(0).getJSONArray("legs").getJSONObject(0).getJSONArray("steps"); 
        PolylineOptions rectOptions = new PolylineOptions(); 
        for (int i = 0; i < steps.length(); i++) { 


         //add start_location 
         JSONObject stepS = steps.getJSONObject(i).getJSONObject("start_location"); 
         rectOptions.add(new LatLng(stepS.getDouble("lat"), stepS.getDouble("lng"))); 

         //add end location 
         JSONObject stepE = steps.getJSONObject(i).getJSONObject("end_location"); 
         rectOptions.add(new LatLng(stepE.getDouble("lat"), stepE.getDouble("lng"))); 

enter image description here

編輯:我發現溶液

rectOptions.addAll(PolyUtil.decode(steps.getJSONObject(ⅰ).getJSONObject ( 「折線」)的getString( 「點」)));

+0

請發佈解決方案,回答不上編輯。謝謝! –

回答

1

解決方案:加入這一行的問題解決了

rectOptions.addAll(PolyUtil.decode(steps.getJSONObject(i).getJSONObject("polyline").getString("points")));