Many technologies have aspired to change the world, but if there’s one that’s really made a difference, it’s digital mapping. Navigation software has replaced the paper map—and changed the way we drive. In the UK, the national driving test recently changed to make understanding how to use an in-car navigation system a requirement before issuing a new driving permit.
You probably use Google Maps to quickly plan routes, but it’s not the only mapping tool out there. iPhone and Mac users typically use Apple Maps. But another option is Microsoft’s Bing Maps, which offers and a set of navigation APIs ready for use in your code, alongside tools for working with spatial data and a web control for displaying map data in browsers and on mobile devices. It’s not just a map website as you may think. (Google offers similar APIs and tools for Google Maps, of course.)
Using Bing Maps APIs for transport logistics
One of the more interesting areas that Microsoft is exploring with its Bing Maps APIs is support for logistics applications. There’s a lot to consider when building logistics software, especially when you need to mix routing, timing, road conditions, and road restrictions that affect trucks. After all, you don’t want drivers rushing to make deliveries avoid traffic jams by driving a truck under a low bridge – and damaging their trucks as a result.
The most obvious set of APIs for logistics includes Bing’s navigation and routing tools. Algorithmic routing is about more than getting from A to B; it’s key to how businesses schedule trucks’ loads and how your home shopping deliveries arrive in the promised time slot. Under the hood of routing APIs are complex mathematical problems, including variants of the classic “traveling salesman”: finding the optimum route that ensures a truck reaches all the planned destinations in the minimum time and the minimum distance.
The economics of many delivery services depend on these algorithms, because driver and company pay depends on the number of packages delivered. If you’re going to make any profit in a low-margin business, having the best possible route optimization is essential. You don’t need to go to the extreme of banning left turns (if you’re in a country that drives on the right), but you can take advantage of cloud compute resources to solve what are at heart complex mathematical problems.
The traveling salesman is an API
Bing Maps’s APIs include tools for calculating distance matrices, a way of choosing the optimum route between several points. By defining a set of origins and destinations, the API calculates routes and travel times, including using predictive traffic. Users can choose driving, walking, and public transit options, giving plenty of options beyond the basic traveling salesman. Perhaps you’re building an app for a public transit service, wanting to deliver optimum routes for commuters getting to their offices, or for tourists planning daytrips in an unfamiliar city.
Using the Bing Maps Distance Matrix API is easy enough, with
POST RESTful requests. More complex queries use asynchronous requests, though they only support driving with a start time. Results can have up to 625 origin-destination pairs; so queries can cover everything from one start and 625 destinations to 25 starts and 25 destinations. Microsoft recommends using synchronous requests for when you’re not using start times, or if you’re calculating driving times for up to ten origin-destination pairs. It recommends using asynchronous requests for up to 100 pairs when driving. More complex requests need to be delivered in chunks, breaking up the number of origin-destination pairs across multiple queries.
To use the Bing Maps API, you need to convert addresses into coordinates using geocoding tools. Once you’ve got origin and destination details, you can use them to construct a JSON payload for your request, along with the travel mode, any start and end times, and the resolution of any time histogram you’re requesting (an interval of 15, 30, 45, or 60 minutes). Other options let you choose imperial or metric units, as well times in minutes or seconds.
The calculate results are collated in a JSON document. Instead of delivering the entire result set, the API response is a URL, from which the app can download the response data.
Building a logistics-based navigation service isn’t a matter of using one API or one control, and it’s certainly not one that’s driven by a single algorithm. After all, you’re juggling a mix of requirements, from vehicle size to delivery urgency. Building an app that gives you the most efficient route between destinations is all very well, but what if you’ve got a time-dependent delivery that might be one of the furthest stops?
With queries supporting several different destination-origin pairs, you can get results for possible routings that let you prioritize certain deliveries, while keeping overall travel time to a minimum. It might not be the optimum route, but it’s likely to be shorter than one calculated manually. Once you’ve used the Distance Matrix API to generate a list of optimum routes between your destinations, you convert the ordered results into a list of waypoints that will generate the optimum route for your journey.
Bing offers an enterprise mapping service
The Distance Matrix API is only one of many enterprise-focused APIs coming from Bing. Some key logistics APIs have been announced but aren’t shipping yet. One of these is the ability to use road distances for tracking, snapping coordinates onto the road network. This will let your code inform drivers of speed limits and improve tracking results for customers waiting for deliveries. Another will use truck route details from navigation providers to route trucks away from low bridges, weight restrictions, narrow roads, and residential roads.
Calculating mapping data is only part of the story; you still need to display those routes in navigation and mapping apps. That’s where the rest of Bing Maps’s tools and APIs come in to play. Microsoft provides a web-based interactive SDK for experimenting with visualizations, such as adding a traffic layer to a map or showing how directions are displayed to a driver.