【问题标题】:Plotting Polylines using Snap to Road in Android Studio在 Android Studio 中使用 Snap to Road 绘制折线
【发布时间】:2016-05-31 23:29:59
【问题描述】:

大家好,你能帮我如何绘制折线吗 现在我有我从 googlemap 得到的 json 我的问题是如何使用这个 json 绘制折线

{
  "snappedPoints": [
    {
      "location": {
        "latitude": 14.554309626417714,
        "longitude": 121.01901383856206
      },
      "originalIndex": 0,
      "placeId": "ChIJ62cMsw_JlzMRCXM5jZU83BM"
    },
    {
      "location": {
        "latitude": 14.554430199999995,
        "longitude": 121.01905140000001
      },
      "placeId": "ChIJ62cMsw_JlzMRCXM5jZU83BM"
    },
    {
      "location": {
        "latitude": 14.5544967,
        "longitude": 121.01907999999997
      },
      "placeId": "ChIJ62cMsw_JlzMRCXM5jZU83BM"
    },
    {
      "location": {
        "latitude": 14.554658699999997,
        "longitude": 121.01916489999999
      },
      "placeId": "ChIJ62cMsw_JlzMRCXM5jZU83BM"
    },
    {
      "location": {
        "latitude": 14.55596745847264,
        "longitude": 121.02005815511896
      },
      "originalIndex": 1,
      "placeId": "ChIJ62cMsw_JlzMRCXM5jZU83BM"
    }
  ]
}

我已经把它转成字符串了,

  RequestQueue requestQueue = Volley.newRequestQueue(this);
        String url = String.format("https://roads.googleapis.com/v1/snapToRoads?path=" + EncodingSnap + "&interpolate=true&key=AIzaSyBNixSdb4ofwpeXzZ7_MXoKnrps352Ji7U");
        JsonObjectRequest jsObjRequest = new JsonObjectRequest
                (Request.Method.GET, url, null, new com.android.volley.Response.Listener<JSONObject>() {

                    @Override
                    public void onResponse(JSONObject response) {
                        SnapToRoadInfo scheduleRequest = new Gson().fromJson(response.toString(), SnapToRoadInfo.class);


                    }
                }, new com.android.volley.Response.ErrorListener() {


                    @Override
                    public void onErrorResponse(VolleyError error) {
                        // TODO Auto-generated method stub
                        Log.e("Error", error.toString());
                    }
                });
        requestQueue.add(jsObjRequest);

我使用 Volley 序列化代码并将其发送到谷歌地图 api,然后,现在我有结果,现在如何解码?

【问题讨论】:

    标签: java google-maps android-studio


    【解决方案1】:

    检查this library中的Poly解码和编码

    示例代码:

        List<LatLng> list = PolyUtil.decode(encodedLine);
        PolylineOptions options = new PolylineOptions().width(10).color(Color.BLUE);
        options.addAll(list);
    
        mMap.addPolyline(options);
    

    【讨论】:

    • 实际上我正在使用我需要的是一个你如何给我这个例子?
    • 添加了示例代码。如果那是你所要求的。
    • 尝试使用您的代码,但它给了我一个致命错误,我创建了自己的方法,现在我使用 gson 进行解析并将其转换为 latlang ,我也使用 volly 进行序列化并将其发送到捕捉点。
    • 您从上面的 JSON 响应中使用哪个纬度和经度?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-17
    • 1970-01-01
    • 1970-01-01
    • 2016-08-17
    • 1970-01-01
    • 2019-10-16
    相关资源
    最近更新 更多