Skip to main content
Skip to main content
Maps

Microsoft Maps Blog

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 possibilities 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.

 

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

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.



Microsoft Maps

Explore everything that the Microsoft Maps Platform has to offer

Back to top