谷歌地图方向Api返回错误的指示?

时间:2016-08-22 18:33:14

标签: android google-maps maps map-directions

我在Directions API的两个点之间得到了响应并解析了它并在地图上绘制了Polyline,但问题是在建筑物上划线

绘制折线的代码:

 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(&#34;折线&#34;。)的getString(&#34;点&#34)));

1 个答案:

答案 0 :(得分:1)

解决方案:添加此行解决了问题

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