title: Optimize path with waypoints based on least distance google directions android
body: <p>I was using google directions api to get the route between two latlng points and plotting it on a google map. The issue is that i can optimize the route when adding waypoints but i can't control the optimization criteria. The code i am using for creating the request url is :</p>
  
  <pre><code>private String getDirectionsUrl(LatLng origin, LatLng dest) {
  
      // Origin of route
      String str_origin = "origin=" + origin.latitude + "," + origin.longitude;
  
      // Destination of route
      String str_dest = "destination=" + dest.latitude + "," + dest.longitude;
  
      // Sensor enabled
      String sensor = "sensor=false";
  
      // Waypoints
      String waypoints = "";
      for (int i = 0; i &lt; markerPoints.size(); i++) {
  
          LatLng point = (LatLng) markerPoints.get(i);
          if (i == 0)
              waypoints = "waypoints=optimize:true|";
          if (i == markerPoints.size() - 1) {
              waypoints += point.latitude + "," + point.longitude;
          } else {
              waypoints += point.latitude + "," + point.longitude + "|";
          }
      }
  
      // Building the parameters to the web service
      String parameters = str_origin + "&amp;" + str_dest + "&amp;" + sensor + "&amp;" + waypoints + "&amp;mode=driving&amp;key=YOUR_API_KEY";
  
  
      // Output format
      String output = "json";
  
      // Building the url to the web service
      String url = "https://maps.googleapis.com/maps/api/directions/" + output + "?" + parameters;
  
      return url;
  }
  </code></pre>
  
  <p>In short, i want to add optimization criteria in this string. Is it possible or do i have to enable alternate routes and manually calculate the travel distance of each path and choose the shortest?</p>