The solution was simple.
This may help someone in the future if you are looking for such a feature.
This method is called after the google direction API returns the route from location A to B directionPoints is a list points in a route.
public void handleResult(ArrayList<LatLng> directionPoints) { PolylineOptions rectLine = new PolylineOptions().width(3).color(Color.RED); for(int i = 0 ; i < directionPoints.size() ; i++) { rectLine.add(directionPoints.get(i)); }
UPDATE
Json answer from Google Direction API
"routes" : [ { "bounds" : { "northeast" : { "lat" : 27.7136953, "lng" : 85.32216629999999 }, "southwest" : { "lat" : 27.7103725, "lng" : 85.3214952 } }, .... etc
Therefore, I used this lat and lng binding as a parameter of LatLngBounds.Builder .
JSONObject jsonBound = ((JSONObject)jRoutes.get(i)).getJSONObject("bounds"); JSONObject jsonSouthWest = jsonBound.getJSONObject("southwest"); JSONObject jsonNorthEast = jsonBound.getJSONObject("northeast"); LatLng boundSouthWest = new LatLng(jsonSouthWest.getDouble("lat"),jsonSouthWest.getDouble("lng")); LatLng boundNorthEast = new LatLng(jsonNorthEast.getDouble("lat"),jsonNorthEast.getDouble("lng")); ArrayList<LatLng> bounds = new ArrayList<LatLng>(); bounds.add(boundNorthEast); bounds.add(boundSouthWest);
and included these points in LatLngBounds.Builder
source share