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.
#1 by Anonymous on October 5, 2011 - 11:56 am
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?
#2 by rbrundritt on October 8, 2011 - 12:04 pm
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();
});
#3 by brettcawley on November 19, 2012 - 12:16 pm
The above didn’t work for me so instead I used
“Microsoft.Maps.loadModule(“RouteServiceHelper”, { callback: CalculateRoute });” – Cheers!
#4 by Diego on May 17, 2013 - 5:59 pm
Great! But this works on Static maps to?
#5 by rbrundritt on May 17, 2013 - 6:02 pm
No, this is only for the interactive map control.
#6 by markafisher92 on May 17, 2013 - 6:15 pm
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?