MrDroid MrDroid - 3 months ago 22
Android Question

Google Maps Direction Api Return wrong directions?

I got Response between two points from Directions API and parsed it and draw Polyline on the map but the problem is the line being draw over building

The code to draw the polyline:

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")));


enter image description here

EDIT : I found the solution

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

Answer

Solution : adding this line solved the problem

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