I want to parse the entire JSON file that contains many JSONObjects 
"steps". I need to extract all polylines and their points. However, it 
returns only the very first value and nothing more. Is anything wrong with 
my loop or I just parse the JSON file wrongly? Thx

public void parseDirect(String response) {

        PolylineOptions polylineOptions = new PolylineOptions();
        List<LatLng> movements = new ArrayList<>();
        try{
            JSONObject json = new JSONObject(response);
            //Retrieve routes from response
            JSONObject jsonRoute = json.getJSONArray("routes").getJSONObject(0);
            //Retrieve legs from routes
            JSONObject legs = jsonRoute.getJSONArray("legs").getJSONObject(0);
            //Retrieve steps from legs
            JSONArray steps = legs.getJSONArray("steps");
            final int numSteps = steps.length();
            JSONObject step;
            //Retrieve points from steps
            for (int i = 0; i < numSteps; i++) {
                step = steps.getJSONObject(i);
                String pontos = 
step.getJSONObject("polyline").getString("points");
                movements.addAll(PolyUtil.decode(pontos));
            }

//            movementsTest.add(new LatLng(52.4634252,-1.8861262));
//            movementsTest.add(new LatLng(52.4761324,-1.8608113));
//            movementsTest.add(new LatLng(52.4634252,-1.8689613));

            polylineOptions.color(Color.RED);
            polylineOptions.width(10);
            polylineOptions.addAll(movements);

            mMap.clear();
            mMap.addPolyline(polylineOptions);
            Log.i("parser", "parseDirect: " + movements.toString());
        }catch(Exception ex){
            Log.d("DirectionErr",ex.getMessage());
        }

        //make use of movements object here
    }



-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jackson-user/f929c044-d9ab-4b97-8f9b-10cbea5f27e8%40googlegroups.com.

Reply via email to