Bing Maps Directions Manager appears to be taking traffic conditions into account when generating a route

Tom 26 Reputation points
2025-08-01T14:28:02.91+00:00

I'm having an issue where I'm using the Bing Maps V8 controls and I'm getting different routes on a map that appears to be related to the traffic conditions on the route. I have setup the DirectionsManager to set the route optimization to shortestTime which should says "The route is calculated to minimize the time. Traffic information is not used." in the documentation.

var map = new Microsoft.Maps.Map(document.getElementById('myMap'), {
    /* No need to set credentials if already passed in URL */
    center: new Microsoft.Maps.Location(-25.746000, 28.187100),
    zoom: 12
});

Microsoft.Maps.loadModule('Microsoft.Maps.Directions', function () {
    var directionsManager = new Microsoft.Maps.Directions.DirectionsManager(map);

    // Set Route Mode to driving
    directionsManager.setRequestOptions({ 
		maxRoutes: 1,
        routeDraggable: false,
        distanceUnit: Microsoft.Maps.Directions.DistanceUnit.km,
        routeMode: Microsoft.Maps.Directions.RouteMode.driving,
        routeOptimization: Microsoft.Maps.Directions.RouteOptimization.shortestTime,
        routeAvoidance: Microsoft.Maps.Directions.RouteAvoidance.none 
	});

    var waypoint1 = new Microsoft.Maps.Directions.Waypoint({ address: 'Pretoria', location: new Microsoft.Maps.Location(-25.746000, 28.187100) });

    var waypoint2 = new Microsoft.Maps.Directions.Waypoint({ address: 'Johannesburg', location: new Microsoft.Maps.Location(-26.201500, 28.045500) });

    directionsManager.addWaypoint(waypoint1);
    directionsManager.addWaypoint(waypoint2);
	directionsManager.addWaypoint(waypoint1);

    // Set the element in which the itinerary will be rendered
    directionsManager.setRenderOptions({ itineraryContainer: document.getElementById('printoutPanel') });

    directionsManager.calculateDirections();
});

This is the route generated an hour ago.

enter image description here

This is the route generated a few minutes ago.

enter image description here

You can see that 2 different routes are generated. The second image is the best route and the reason it was different earlier appears to be traffic conditions. I was under the impression from the documentation that the route would be calculated to minimize the time and would not take traffic into account.

How should I setup the directionsManager to get a route that does not take traffic conditions into account?

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

1 answer

Sort by: Most helpful
  1. rbrundritt 21,191 Reputation points Microsoft Employee Moderator
    2025-08-01T16:12:42.04+00:00

    Route path calculations are generally done using a genetic heuristic algorithm which is a fast approximation and may not be 100% best solution every time but may be the 99% best at times. Calculating the absolute best route requires a brute force calculation which could take a very long time to calculate given the scale of the road network available in Bing Maps (global). With geneic algorithms, if you run the same calculation multiple times it is not unusual to get slightly different results. The travel times of each line in your first image are actually fairly close, and both are logical routes that someone might take. I don't suspect it is actually taking traffic into consideration here.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.