In the Bing Maps v7 control there is the Directions module which allows you to calculate a route with up to 15 waypoints and also generate a nice UI of the resulting directions. Before this module we would have to access the Bing Maps Routing REST service directly to calculate routes. For some this may be still may be the preferred method of requesting routes. The REST services allow you to calculate routes with up to 25 waypoints. In some situations support for routing between a larger number of waypoints may be required. This is where this module comes in. It wraps the Bing Maps Routing REST service and allows you to calculate a route with an unlimited number of waypoints. It accomplishes this by breaking the waypoints into batches and matching multiple routing requests. The results are then merged together into one route response.
This module is easy to use and has two public methods; GetRoute and IsProcessing. The GetRoute method takes in an array of waypoints, a Bing Maps key, a set of route options and a callback method. The IsProcessing method simply checks to see if the RouteServiceHelper class is processing a calculating a route.
This module, along with complete source code and an example implementation can be downloaded here. This module is part of the Bing Maps v7 Module community project on CodePlex, check this project out for other cool and useful Bing Maps v7 modules..
Below is an example of a route with 32 waypoints that was generated using this module.
Currently this module is limited to driving and walking directions, transit directions are not supported. User context information and route tolerances are also not supported. If this functionality is required outside of the Bing Maps V7 control the code in this module can easily be adopted to work on its own in other programming languages. This may be useful in cases where this functionality is needed in backend systems.
Hi,
Thanx for nice solution and code,
1) I’m trying to eliminate “Calculate Route” button click so that page can display Route on very first page load by calling CalculateRoute() in function GetMap() ‘s last line. but getting error “RouteServiceHelper” not Initialized.
How I can achieve this functionality?
You should wait until the RouteServiceHelper is loaded before calling it. You can add functionality for this in the callback function when the RouteHelper module is loaded. For example change:
Microsoft.Maps.loadModule(“RouteServiceHelper”);
to
Microsoft.Maps.loadModule(“RouteServiceHelper”, function(){
CalculateRoute();
});
The above didn’t work for me so instead I used
“Microsoft.Maps.loadModule(“RouteServiceHelper”, { callback: CalculateRoute });” – Cheers!
Hello Sir, i am developing an application where i have to find a shortest path among various location. for example a salesman problem. Among multiple direction i have to find the shortest path. could you please help me to get a right approach using Java script. I am using Bing Map V7 service.
Take a look at this code sample: http://code.msdn.microsoft.com/windowsdesktop/Bing-Maps-Trip-Optimizer-003021ae#content
Great! But this works on Static maps to?
No, this is only for the interactive map control.
Good article!
Thanks for taking the time to always provide us with the latest update to Bing Maps V7. I just started diving into this a few months ago, and your blogs have been very helpful. Is this the same directions module that puts cool icons in a sidebar for each step of a route?