我在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")));
编辑:我找到了解决方案
rectOptions.addAll(PolyUtil.decode(steps.getJSONObject(ⅰ).getJSONObject(&#34;折线&#34;。)的getString(&#34;点&#34)));
答案 0 :(得分:1)
解决方案:添加此行解决了问题
rectOptions.addAll(PolyUtil.decode(steps.getJSONObject(i).getJSONObject("polyline").getString("points")));