【问题标题】:Google Maps Direction Api Return wrong directions?Google Maps Direction Api 返回错误的方向?
【发布时间】: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


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-26
    • 2015-10-19
    • 2013-01-12
    • 1970-01-01
    • 1970-01-01
    • 2015-08-07
    • 2019-03-13
    • 2012-06-05
    相关资源
    最近更新 更多