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 beMicrosoft.Maps.Directions.RouteOptimization.shortestTime
- Also, the distance units should be
Microsoft.Maps.Directions.DistanceUnit.km
as per the documentation.