DEV Community

Cover image for What is Routing?
Ruanna for TomTom Devs

Posted on • Edited on

What is Routing?

Introduction Into Routing

With location services you can retrieve your current location, the location of a place you are trying to find, and the turn-by-turn directions to get there. Providing directions between two or more locations is routing.

The TomTom Routing API enables a number of routing scenarios. It allows routing to be performed with a list of points of interest or calculating a range based on mode of transportation, time limits, and energy consumption. The routing information can be packaged in many common data formats. TomTom also has a Software Development Kit (SDK) available for the web, iOS, and Android.

In this article we’ll look at:

• Route calculation
• Displaying routes on a map
• Range routing

Route Calculation

The TomTom API needs at least two waypoints (a starting and ending point) to calculate a route. Up to 150 waypoints can be given to the API for calculating a route. The starting and ending points can be the same (as would be the case with a round trip), but you need to provide at least one additional waypoint to make the route calculation.

The routing calculation can be modified to better fit the preferences for a trip. The API will make calculations from some general assumptions (that one is travelling in a car, the car will travel at speeds up to the posted speed limit, and so on) unless a route calculation request specifies otherwise.

Information that will modify a route calculation may include the mode of travel (walking, cycling, driving a truck, taking a taxi) and historical traffic conditions for the time of the trip, and even other characteristics of the vehicle when given to the API. For trucks, the maximum speed of the truck, its size, weight, and cargo type are additional factors that can affect the route since some roads have limits on vehicle sizes, weights, and the type of cargo that the truck carries. This is a response produced from a routing search between two points.

Alt Text

The route calculation response shows that the calculation was performed assuming that the mode of travel is by car and is a distance of 16.6 kilometers. The travel time and delay due to traffic conditions is also shown. The traffic delay here being zero seconds means that traffic along the route is good.

Since this trip is only connecting two points, the trip has a single leg. As more points are added, the number of legs in the trip increases. The coordinates that make up the path are in a list named “points.” The complete contents of the point list is not shown here. A sample of a few of the items in the list are shown in the box to the right of the result; each point is a latitude and longitude coordinate.

The routing calculation can prioritize the pathway that it takes according to the type of route that is requested. The fastest route can be requested to minimize driving time. The shortest route can be requested to minimize driving distance. Asking for the most economical route will give the path that uses the least amount of fuel or battery power. The calculation can also prioritize a route for what might be the most fun (choosing a pathway that has the most hills and curves to drive on).

Route calculation is helpful for determining an optimized order in which to visit a set of places. If the API is asked to compute the best order, it will reorder the points visited to minimize the overall trip length. The starting point will be the same even after reordering. For the best results, allow the API to reorder the points when the route type requested is for the shortest trip.

The routing information is not limited to getting the raw set of points that make up the route. Turn by turn directions are available. The instructions can be formatted for easy processing by a computer, as text to be displayed to a user or as text where some elements of the instructions are marked and could be presented with special formatting.

The response when instructions are requested adds a new element named guidance. The guidance element holds two pieces of information. It holds the turn-by-turn directions for the trip and the summarized instructions where each instruction summary covers a segment of the trip that could cover multiple roads.

Alt Text

There is usually more than one way to get from point A to B. If more than one route is needed, alternative routes can be requested. With a route calculation request, a maximum number of routes can be specified. In addition to the primary route, the API will produce a number of alternative routes (but no more than the maximum specified).

It is possible that the number of alternative routes available will be less than the maximum specified. The tolerable amount of time or distance deviation from the primary route can also be selected. The result will have multiple routes. The summary of each route shows the length of the route and the estimated drive time. The alternative routes also provide the coordinate at which deviation from the primary route occurs.

Alt Text

Displaying a Route on a Map

The TomTom SDK contains functionality for displaying a map and overlaying graphics on it. The graphics can be lines, shapes, images and text. Routes are essentially collections of lines and can be displayed on the map as lines. The starting and ending points for a trip can be marked with images.

Alt Text

Range Routing

Range routing finds the boundaries of how far one can go from a point within a budget. The budget can be a time limit or energy limit. The result that is returned is a series of coordinates that define the boundary in which one could travel. The range calculations will be based on travel by car unless a different mode of travel is requested. The accuracy of the results can be improved as more information on the vehicle's efficiency are provided with the request.

Range Routing with a Time Limit

With range routing with a time limit the API will calculate the boundaries of how far one could travel from a starting point within a time range. The calculation will assume that the mode of travel is a car and that maximum speeds will be the posted speed limits. It can also perform calculations for walking, cycling, and other modes of travel. The results of this calculation are a list of coordinates that form the travel boundary around the starting point.

Alt Text

Range Routing with an Electricity Budget

The API can calculate how far an electric vehicle can travel within an energy budget. The routing API must be told it is performing range routing for an electric vehicle. The energy budget for a trip is measured in kilowatt hours.

The amount of energy that a car uses to travel can differ according to the speed of the vehicle; for example, the same vehicle could use a different amount of energy driving a kilometer on a road at 20 kph than it does travelling the same road and the same distance at 60 kph. To account for this, the vehicle's rate of energy consumption at various speeds can be used in the range calculation.

While range routing will work if only the energy consumption rate at one speed is available, the calculation results will be more accurate if more information is available. The results from this calculation are structured identical to those from a time budget calculation.

Range Routing with a Fuel Budget

Calculating the distance that a vehicle could travel on a certain amount of fuel is similar to the electric car scenario. The routing API for this scenario would be told that the range routing is being performed for a combustion engine. The budget for the range is specified in liters of fuel. The rate at which the vehicle uses fuel at various speeds is also needed with results being more accurate if more information on fuel consumption rate is available.

Display Range Routing

The result of a range route can also be displayed on a map. Instead of a line the range result translates to a polygon. When placed on a map it covers the areas that can be reached within budget on the map.

Alt Text

Conclusion

A developer can quickly build solutions for location based scenarios with the TomTom Route Calculation services and SDK. It has the flexibility to work with a variety of scenarios and modes of travel. The results can be formed in popular formats used for application development (JSON, XML, and JSONP) and with the TomTom SDK search results can be shown visually on a map.

Want to Learn More?

• Check out the TomTom Developer Portal for a hub of tools and resources
• Learn more about the TomTom Routing API and Extended Routing API
• Visit the TomTom Developers blog for more tutorials, thought leadership, and other topics

Note: This article was originally published on developer.tomtom.com. The original author is Shannon Stroud.

Top comments (0)