Beating Traffic with Bing Maps’ Route Optimization APIs

NOTE: An updated version of this article can be found in the Microsoft Maps Blog.
https://www.microsoft.com/en-us/maps/news/beating-traffic-with-bing-maps-route-optimization-apis

The ideal route optimization software works in real-time to give users contextually relevant routes, accounting for traffic, road closures, and even vehicle specifications. Whether you’re on the road for a personal errand or managing a large fleet of agents, Bing Maps API’s free (with a basic key) routing suite goes the extra mile so you don’t have to.

Travel faster with the Routes API

The Bing Maps Routes API is a powerful REST service that can calculate efficient routes for multiple modes of transportation, whether that’s on foot, driving, or even public transit. One of the most useful advantages of this route optimization API is the ability to solve the ‘traveling salesman problem’ (TSP) with software that accounts for traffic and other real-time factors.

The TSP involves calculating the most efficient way to travel to multiple stops on a route. Finding the best route for a multi-stop journey is already complex enough for a single agent, and it only gets more difficult when you add a fleet of riders with hundreds of different destinations to the equation.

Check out our Routes API blog for an in-depth look at how you can build route optimization software that simplifies the TSP.

Bing Maps Samples: From London To Madrid

Robust mapping applications should be both accurate and adaptable enough to meet changing requirements on the go.

Let’s have a look at how the Routes API meets these standards with a free and interactive Bing Maps API sample.

Our sample revolves around a road trip all the way from London to Madrid. The fun part? You can change waypoints from one location to another, and receive a newly optimized traffic route from the API in seconds. Try it out by dragging the Burgos waypoint to Zaragoza!

Old Route:

a map showing a route leading to Madrid through Burgo

New Route:

a map showing a route leading to Madrid through Zaragoza

Beat traffic your way

Routes aren’t the only thing you can customize with this API!

Developers building route optimization software with the Routes API enjoy full flexibility in terms of the mapping interface. From the color of the path to the titles of different pushpins, everything is customizable.

    var map, directionsManager;

    function GetMap()
    {
        map = new Microsoft.Maps.Map('#myMap', {});

        //Load the directions module.
        Microsoft.Maps.loadModule('Microsoft.Maps.Directions', function () {
            //Create an instance of the directions manager.
            directionsManager = new Microsoft.Maps.Directions.DirectionsManager(map);

            //Create waypoints to route between.
            directionsManager.addWaypoint(new Microsoft.Maps.Directions.Waypoint({ address: 'London, UK' }));
            directionsManager.addWaypoint(new Microsoft.Maps.Directions.Waypoint({ address: 'Paris, FR' }));
            directionsManager.addWaypoint(new Microsoft.Maps.Directions.Waypoint({ address: 'Madrid, ES' }));

            //Set the request options that avoid highways and uses kilometers.
            directionsManager.setRequestOptions({
                distanceUnit: Microsoft.Maps.Directions.DistanceUnit.km,
                routeAvoidance: [Microsoft.Maps.Directions.RouteAvoidance.avoidLimitedAccessHighway]
            });
            
            //Make the route line thick and green. Replace the title of waypoints with an empty string to hide the default text that appears.
            directionsManager.setRenderOptions({
                drivingPolylineOptions: {
                    strokeColor: 'green',
                    strokeThickness: 6
                },
                waypointPushpinOptions: {
                    title: ''
                }
            });

            //Calculate directions.
            directionsManager.calculateDirections();
        });
    }

There are multiple ways of beating traffic with our free route optimization API. In the sample, we’re using the ‘routeAvoidance’ parameter to avoid highways with limited access. You can use the same parameter to avoid ferries, tolls, and border crossings on a given route.  

Alternatively, simply use the ‘timeWithTraffic’ value to minimize the time spent in traffic. Head over to the Routes API documentation to learn more about creating route optimization software that can keep up with your organization’s demands.  

Create your own driving route 

You can create a driving route using the Bing Maps V8 interactive SDK: an intuitive introduction to a colorful world of web maps. Discover more possabilities by going through the code samples in JavaScript or TypeScript and you can also edit the samples, press play then see what changes in real-time. Use the traffic module to add color-coded roads that accurately indicate traffic flow.

Beat traffic with optimized itineraries

What if you’re trying to manage a large fleet with hundreds of waypoints?

The Multi-Itinerary Optimization (MIO) API allows you to create faster routes for hundreds of agents at a time with support for predictive traffic and customizable parameters. Always stay one step ahead of the crowd with a scalable API that can keep up with the needs of your fleet.

This API powers reliable route optimization software that doesn’t just stop at predicting traffic to help you get ahead. Support for additional variables like time windows, agent schedules, and even stop priority is the key to creating a truly bespoke piece of software tailored to your unique day-to-day needs. The API’s automated routing features free operators up and allow them to work on more productive tasks.

The Multi-Itinerary Optimization API is a great fit for a range of different industries. For example,  restaurants and grocers can schedule on-time routes for all of their orders with the click of a button. Similarly, sales agents that have to make multiple stops throughout the day can save time and money with an app that does the heavy lifting for them.

Route Optimization Software Demo

Get a glimpse of the kind of robust route optimization software you can create with a free routing API demo. This interactive API demo includes all of the features one would need for everyday use, including:

  • Route optimization API powered by predictive traffic
  • Dwell time parameters (accounting for the time an agent would spend at a given location)
  • Multiple shifts and agents
  • Options to optimize for travel time or price

an optimized itinerary for two agents

Load a scenario of your choice and find out how the MIO API can scale your mapping solution.

Get traffic incident data

Go beyond predictive traffic flows by creating route optimization software that sees the bigger picture. The Traffic API can be used to get full coverage of all traffic-related incidents an organization might need to know about before sending an agent out.

Developers can use a single URL request to learn about traffic incidents in a given area.

HTTPS URL:

http://dev.virtualearth.net/REST/v1/Traffic/Incidents/37,-105,45,-94?key=YourBingMapsKey


Here’s what the response would look like in JSON

      {   
         "estimatedTotal":131,   
         "resources":[   
            {   
               "__type":"TrafficIncident:http:\/\/schemas.microsoft.com\/search\/local\/ws\/rest\/v1",   
               "point":{   
                  "type":"Point",   
                  "coordinates":[   
                     38.85135,   
                     -94.34033   
                  ]   
               },   
               "congestion":"",   
               "description":"MO-150 is closed between 5th Ave S and Court Dr - construction",   
               "detour":"",   
               "end":"\/Date(1310396400000)\/",   
               "incidentId":210546697,   
               "lane":"",   
               "lastModified":"\/Date(1309391096593)\/",   
               "roadClosed":true,   
               "severity":3,   
               "start":"\/Date(1307365200000)\/",   
               "type":9,   
               "verified":true   
            },   
            {   
               "__type":"TrafficIncident:http:\/\/schemas.microsoft.com\/search\/local\/ws\/rest\/v1",   
               "point":{   
                  "type":"Point",   
                  "coordinates":[   
                     38.85872,   
                     -94.54638   
                  ]   
               },   
               "congestion":"",   
               "description":"Botts Rd is closed between Andrews Rd and 142nd St - construction",   
               "detour":"To go north take US-71 NB to 140th St and go west on 140th St to access Botts Rd- To go south continue west on MO-150 to Thunderbird Rd to 149th St",   
               "end":"\/Date(1315244760000)\/",   
               "incidentId":191097424,   
               "lane":"",   
               "lastModified":"\/Date(1309391096593)\/",   
               "roadClosed":true,   
               "severity":1,   
               "start":"\/Date(1295704800000)\/",   
               "type":9,   
               "verified":true   
            }   
         ]   
      }

The Traffic API’s response is incredibly useful for route optimization software as it lists out all the traffic incidents in the bounding box or radius defined with the URL.

Specific descriptions like ‘construction’ give further insight into why a particular road might be off-limits and allow businesses to make better decisions on the go.  The ‘detour’ parameter is of particular interest here as it saves operators the hassle of having to figure out an alternative route in the event of a closure.

Beat the rush with Bing Maps API

We’re always evolving Bing Maps API with free and exciting new enhancements to our routing and logistics APIs. Beat the rush with a robust mapping solution that can scale to meet your organizational needs with the click of a button. Create a free Bing Maps API key and get started today.   

FAQs

Which calls and requests are supported by the MIO API? 

The MIO API supports both synchronous and asynchronous calls, along with GET and POST requests. Visit the MIO datasheet to learn more.

What kind of apps can I make with Bing Maps API?

From route optimization software to location guessing games, there are many different APIs that can each be used to create innovative apps. Read our fun API projects blog to get inspired.

Can I use other types of imagery for my maps?

Our APIs are backed by a repository of high quality location data. Developers can use Bird’s Eye and Streetside imagery, or even custom map tiles with traffic flows for route optimization with Bing Maps API.