While digging into Bing Maps for route optimization, I discovered that each route with 10 stops can be optimized according to the suggestions provided by Bing Maps. I am working on reordering the waypoints using JavaScript code.
directionsManager = new Microsoft.Maps.Directions.DirectionsManager(map);
directionsManager.setRenderOptions({ itineraryContainer: document.getElementById('directionsItinerary') });
var startWaypoint = new Microsoft.Maps.Directions.Waypoint({
location: new Microsoft.Maps.Location(XX, YY),
});
directionsManager.addWaypoint(startWaypoint);
for (var i = 0; i < 10; i++) {
var waypoint = new Microsoft.Maps.Directions.Waypoint({
location: new Microsoft.Maps.Location(XX, YY),
})
directionsManager.addWaypoint(waypoint);
}
var endWaypoint = new Microsoft.Maps.Directions.Waypoint({
location: new Microsoft.Maps.Location(XX, YY),
});
directionsManager.addWaypoint(endWaypoint);
directionsManager.setRequestOptions({
routeDraggable: false,
routeOptimization: Microsoft.Maps.Directions.RouteOptimization.shortestDistance,
routeMode: Microsoft.Maps.Directions.RouteMode.driving
});
Microsoft.Maps.Events.addHandler(directionsManager, 'directionsUpdated', function(result) {
console.log(result);
});
directionsManager.calculateDirections();
In the 'directionsUpdated' event, the waypoints are not reordered when the API is called. They remain in the same order as sent initially.
I'm now curious if the Bing Map Routes API has the capability to reorder the waypoints when the "optimized" parameter is used, or if it only minimizes the distance between two points?