在Android Studio中使用Snap to Road绘制折线

时间:2016-02-19 11:44:22

标签: java google-maps android-studio

大家好,你们可以帮我看一下如何绘制折线 现在我有我从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,然后,现在我有结果,现在如何解码?

1 个答案:

答案 0 :(得分:1)

this library

中检查多边形解码和编码

示例代码:

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

    mMap.addPolyline(options);