解码不同的折线会返回相同的LatLng列表

时间:2018-08-07 08:58:38

标签: android google-maps

我正在尝试解码不同的折线

JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            try {
                List<Route> routes = new ArrayList<>();
                JSONArray jsonRoutes = response.getJSONArray("routes");

                for (int i = 0; i < jsonRoutes.length(); i++){

                    Route route = new Route();
                    JSONObject jsonRoute = jsonRoutes.getJSONObject(i);
                    JSONObject overview_polyline = jsonRoute.getJSONObject("overview_polyline");

                    String points = overview_polyline.getString("points");
                    route.points = PolyUtil.decode(points);

                    route.startLocations = new ArrayList<>();
                    JSONArray jsonLegs = jsonRoute.getJSONArray("legs");

                    for (int j = 0; j < jsonLegs.length(); j++){

                        JSONObject jsonLeg = jsonLegs.getJSONObject(j);
                        JSONArray jsonSteps = jsonLeg.getJSONArray("steps");

                        for (int k = 0; k < jsonSteps.length(); k++){
                            JSONObject jsonStep = jsonSteps.getJSONObject(k);
                            JSONObject jsonStartLocation = jsonStep.getJSONObject("start_location");
                            route.startLocations.add(new LatLng(jsonStartLocation.getDouble("lat"), jsonStartLocation.getDouble("lng")));
                        }
                    }
                    routes.add(route);
                }

                listener.onDirectionFinderSuccess(routes);

            }catch (JSONException e) {
                e.printStackTrace();
            }

返回的LatLng列表如下

解码结果: Result of decoding

很显然,这些点都被错误地解析了。

我的问题是...有人知道如何解析Google的答案,并将其转换为LatLng对象(不是GeoPoints对象)吗?

0 个答案:

没有答案