Calculate Distance in a Route with webservice RRS feed

  • Question

  • HI,

    trying to get simple number: shortest route by road from address A to B is xx.x kilometers.

    Read whole morning different examples, copied PHP codes and tested. I get nice route instructions etc. from A to B but no distance. 


     $baseURL = "";

      // construct parameter variables for Routes call  
      $wayPoint0 = str_ireplace(" ","%20",$_POST['origin']);  
      $wayPoint1 = str_ireplace(" ","%20",$_POST['destination']);  
      $optimize = "time";  
      $routePathOutput = "Points";  
      $distanceUnit = "km";  
      $travelMode = "Driving";  

      // Construct final URL for call to Routes API  
      $routesURL = $baseURL."/".$travelMode."?wp.0=".$wayPoint0."&wp.1=".$wayPoint1."&optimize=".$optimize."&routePathOutput=".$routePathOutput."&distanceUnit=".$distanceUnit."&output=xml&key=".$key;  


      // Get output from API and convert to XML element using php_xml  
      $output = file_get_contents($routesURL);    
      $response = new SimpleXMLElement($output);  

      // Extract and print number of routes from response  
      $numRoutes = $response->ResourceSets->ResourceSet->EstimatedTotal;  
      echo "Number of routes found: ".$numRoutes."<br>";  


    I haven't been able to find where total distance is calculated ?

    Is there way to define shortest route as main criteria ?

    Sunday, February 23, 2020 7:35 AM

All replies