Driving time and distance API issue

Balasaheb Molawade 136 Reputation points

Hi Team,

We are using the Route API (https://dev.virtualearth.net/REST/V1/Routes/driving) to get information such as route instructions, travel duration, travel distance. Also, we are using the Direction Manager Class for calculating directions and displaying a route on a map.

We are encountering issue for certain addresses while comparing the travel distance and travel duration between Route API and Direction Manager Class.

For example,

Address 1: Am Schlossfeld 5 Marktheidenfeld Main-Spessart Bavaria 97828 Germany (Latitude: 49.8240, Longitude: 9.5500)
Address 2: Schmidmühlener Straße 8 Burglengenfeld Schwandorf Bavaria 93133 Germany (Latitude: 49.2089, Longitude: 12.0316)

In Direction Manager Class, we are passing the (routeOptimization: shortestTime ) as mentioned below. Here, we are getting travel distance value is 233 KM.

            routeMode: Microsoft.Maps.Directions.RouteMode.driving,
            routeOptimization: shortestTime,
            distanceUnit: Microsoft.Maps.Directions.DistanceUnit.kilometers,

Screenshot 1:

In Route API, we are passing the (optimize=time) as mentioned in below link. Here, we are getting the travel distance value is 260 KM.

https://dev.virtualearth.net/REST/V1/Routes/driving?wp.0=Am%20Schlossfeld%205%20Marktheidenfeld%20Bavaria%20GermanyMain-Spessart%2097828%20&wp.1=Schmidm%C3%BChlener%20Stra%C3%9Fe%208%20Burglengenfeld%20Bavaria%20Germany%20Schwandorf%2093133%20&distanceUnit=km&optmz=time&key=(Your Bing Map Key) 

We are getting nearly 30km difference while comparing the Route API and Direction Manager Class. Could you please check and provide guidance on resolving this issue?


Azure Maps
Azure Maps
An Azure service that provides geospatial APIs to add maps, spatial analytics, and mobility solutions to apps.
661 questions
{count} votes

1 answer

Sort by: Most helpful
  1. rbrundritt 16,466 Reputation points Microsoft Employee

    Doing a lot of testing and comparing the generated REST request from the directions manager to your REST request, it appears the main parameter that makes the difference is that the directions manager includes &maxSolns=3 in the request. When I add that to your REST request, the first result is 234km. (Note time of day the request is made makes a difference since real time traffic conditions are used). The routing algorithm likely uses a generic heuristic to calculate the shortest path. Heuristics are fast at estimating the shortest path, but rarely provide the absolute shortest path on the first try. By asking for multiple solutions, you get alternate routes, and in this case, a more optimal solution is found. There isn't much that can be done here, that's just how heuristics work and the only real way to guarantee a better outcome would be a brute force algorithm which would likely take hours to calculate the result, rather than the sub-second response time the routing service currently has.

    A couple things in your code I noticed:

    • When using the directions manager, you have a shortestTime variable, is this set somewhere? If not, this should be Microsoft.Maps.Directions.RouteOptimization.shortestTime
    • Also, the distance units should be Microsoft.Maps.Directions.DistanceUnit.km as per the documentation.
    1 person found this answer helpful.
    0 comments No comments