【发布时间】:2016-08-22 18:33:14
【问题描述】:
我从 Directions 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")));
编辑:我找到了解决方案
rectOptions.addAll(PolyUtil.decode(steps.getJSONObject(i).getJSONObject("polyline").getString("points")));
【问题讨论】:
-
请将解决方案发布为答案而不是编辑。谢谢!
标签: android google-maps maps map-directions