Build Different

Turning Location Data Points into Information About Your Fleet

Mike Mackrory
Mar 28, 2019 • Last edit on Sep 20, 20228 min read
Semi trucks traveling on a highway

Modern technology can provide us with a wealth of data about the location of vehicles and their states, but sometimes the path between those data points and the useful and actionable information isn’t easy to find. In this article, I’m going to introduce you to some of the APIs available from TomTom and demonstrate how you can leverage them to turn location data points into actionable information about your fleet.

We’ll look at some examples to determine the location of a specific vehicle in an understandable human form and then identify the route the vehicle followed to get there. Finally, we’ll investigate how to find out additional information about the route, and even identify if the vehicle violated speed limits while completing the route.

I’ll be sharing direct API calls to keep this article as coding language-agnostic as possible; however, any modern web language can access these APIs.

This article focuses on how to use the TomTom Search and Routing APIs, but developers also have access to Web and Mobile SDKs which contain similar functionality. You can learn more about each of the SDKs from the following links:

Fig. 1 Application Details

Each of the examples below includes the phrase ReplaceWithYourAPIKeyHere. You’ll need to replace that phrase with the Consumer API Key from your unique application. Let’s see where our drivers have been taking the corporate vehicles.

Where Are They Now?

The scenario is this: We have a vehicle which is carrying a GPS locator and sending location information to our system in the form of latitude and longitude pairs. For this example, we’ll be working with the following pair of coordinates:


Let’s see if we can find the address, and then we’ll see if we can also get the nearest cross street. The base URL is, and we’ll be accessing the search API. The current version of this API is 2, and we’re going to be performing a reverse geocoding option.,-122.627832.json?key=ReplaceWithYourAPIKeyHere

Fig. 2 Example URL for Reverse GeoCoding

If you receive a response similar to the one below, you’ll need to ensure that your API key is entered correctly.

<h1>Developer Inactive</h1>

Fig. 3 Error Received When the API Key is Incorrect

The JSON path parameter indicates that we would like to receive a response in JSON format. If this parameter is omitted, the default format of XML is used. The response from the URL above is shown below.

2 "summary":{
3 "queryTime":134,
4 "numResults":1
5 },
6 "addresses":[
7 {
8 "address":{
9 "buildingNumber":"3527",
10 "streetNumber":"3527",
11 "routeNumbers":[
13 ],
14 "street":"SE Hawthorne Blvd",
15 "streetName":"SE Hawthorne Blvd",
16 "streetNameAndNumber":"3527 SE Hawthorne Blvd",
17 "countryCode":"US",
18 "countrySubdivision":"OR",
19 "countrySecondarySubdivision":"Multnomah",
20 "municipality":"Portland",
21 "postalCode":"97214",
22 "country":"United States Of America",
23 "countryCodeISO3":"USA",
24 "freeformAddress":"3527 SE Hawthorne Blvd, Portland, OR 97214",
25 "countrySubdivisionName":"Oregon"
26 },
27 "position":"45.512046,-122.627833"
28 }
29 ]

Fig. 4 Reverse Geocoding Response

All right—I now know that the driver has parked the vehicle at 3527 SE Hawthorne Blvd in downtown Portland. If I’m not mistaken, Blue Star Donuts is right down the street. (I hope they bring a couple back to the office.)

While we wait for the donuts, let’s see if there is a way to get more information about exactly where they are. Hawthorne Blvd is a pretty long road. I’d like to know which cross street they’re closest to.,-122.627832.json?key=ReplaceWithYourAPIKeyHere

Fig. 5 Example URL for Reverse GeoCoding with Cross Street Information

2 "summary":{
3 "numResults":1,
4 "queryTime":209
5 },
6 "addresses":[
7 {
8 "address":{
9 "streetName":"SE 35th Pl & SE Hawthorne Blvd",
10 "crossStreet":"SE 35th Pl",
11 "municipalitySubdivision":"Richmond, Portland",
12 "municipality":"Portland",
13 "countrySecondarySubdivision":"Multnomah",
14 "countryTertiarySubdivision":"Portland East",
15 "countrySubdivision":"OR",
16 "postalCode":"97214",
17 "countryCode":"US",
18 "country":"United States Of America",
19 "countryCodeISO3":"USA",
20 "freeformAddress":"SE 35th Pl & SE Hawthorne Blvd, Portland, OR 97214",
21 "countrySubdivisionName":"Oregon",
22 "street":"SE Hawthorne Blvd"
23 },
24 "position":"45.51204,-122.62763"
25 }
26 ]

Fig. 6 Reverse Geocoding Response

The cross street option is especially useful in cases where the address doesn’t yield exact information, or if a precise location is necessary for emergency situations. Let’s see if we can find out more about how they traveled to this exact location.

How Did They Get There?

Our next challenge is to reconstruct the route the vehicle traveled to get from one location to another. We’ll use the Routing API to work this out. If we submit a POST request, we’re able to include a list of supporting points that allow us to reconstruct the route based on where the vehicle traveled. We can also include the start and end time to determine if there were any delays along the way.

We’ll use the following URL and then pass in a JSON body which includes the supporting point and other critical parameters. Here’s the information we know about the driver and the route they took:

  • The driver started at the PDX airport (45.5868227,-122.5937596) and ended up at the Blue Star Donut Shop (45.512077,-122.627832).
  • We have a series of points as pairs of latitude and longitude values, along which the vehicle drove.,-122.5937596:45.512077,-122.627832/json?key=ReplaceWithYourAPIKeyHere

Fig. 7 Base URL to Reconstruct Route with Supporting Points

The request body is in JSON format, so we’ll pass along a Content-Type header set to application/json. The body we’ll pass in with the request is shown below. I thinned out the list of supporting points to keep the snippet small.

2 "supportingPoints":[
3 {
4 "latitude":45.58355,
5 "longitude":-122.58545
6 },
7 {
8 "latitude":45.52641,
9 "longitude":-122.61544
10 },
11 {
12 "latitude":45.51287,
13 "longitude":-122.62296
14 },
15 {
16 "latitude":45.51204,
17 "longitude":-122.62782
18 }
19 ]

Fig. 8 Passing a Collection of Supporting Points to Accurately Map the Route

The following response is typical of what you can expect to receive from the Routes API with this request.

2 "formatVersion":"0.0.12",
3 "copyright":"Copyright 2018 TomTom International BV. ...",
4 "privacy":"TomTom keeps information that tells us how ...",
5 "routes":[
6 {
7 "summary":{
8 "lengthInMeters":12201,
9 "travelTimeInSeconds":1479,
10 "trafficDelayInSeconds":0,
11 "departureTime":"2018-09-24T23:01:26-07:00",
12 "arrivalTime":"2018-09-24T23:26:04-07:00"
13 },
14 "legs":[
15 {
16 "summary":{
17 "lengthInMeters":12201,
18 "travelTimeInSeconds":1479,
19 "trafficDelayInSeconds":0,
20 "departureTime":"2018-09-24T23:01:26-07:00",
21 "arrivalTime":"2018-09-24T23:26:04-07:00"
22 },
23 "points":[
24 {
25 "latitude":45.58671,
26 "longitude":-122.59387
27 },
28 {
29 "latitude":45.58638,
30 "longitude":-122.59324
31 },
32 //Data points removed to reduce space
33 {
34 "latitude":45.51287,
35 "longitude":-122.62588
36 },
37 {
38 "latitude":45.51204,
39 "longitude":-122.62783
40 }
41 ]
42 }
43 ],
44 "sections":[
45 {
46 "startPointIndex":0,
47 "endPointIndex":10,
48 "sectionType":"TRAVEL_MODE",
49 "travelMode":"other"
50 },
51 {
52 "startPointIndex":10,
53 "endPointIndex":213,
54 "sectionType":"TRAVEL_MODE",
55 "travelMode":"car"
56 }
57 ]
58 }
59 ]

Fig. 9 Reconstructed Route Based on Supporting Points

The full route information includes a complete set of points which you can plot on a map. The route also includes a summary section which provides details about the distance of the route, the time to travel the route, and an adjustment based on traffic.

Departure time and arrival time are optional parameters and mutually exclusive. These are useful if you want to plot a route based on specific departure time, or if you need to arrive by a particular time and need to know the best time to leave.

Exploring Additional Details of the Route

If you have a tracking system which includes speed readings from the vehicle, then you can compare these readings against speed information using the returnSpeedLimit parameter with the reverse geocoding request. We’ll pick a point on the route, and pass this to the Search API.,-122.596347.json?key=ReplaceWithYourAPIKeyHere&returnSpeedLimit=true

Fig. 10 Example URL for Reverse GeoCoding with Speed Limit Information

If you look at the response below, you’ll see that in addition to the address information, we also have a speed limit parameter which indicates the speed limit on this stretch of road. We can perform this query for each point of the route, and compare it programmatically with the speed data from the vehicle, allowing us to determine if any speed violations occurred en route to the destination.

2 "summary":{
3 "queryTime":109,
4 "numResults":1
5 },
6 "addresses":[
7 {
8 "address":{
9 "routeNumbers":[
10 "I-84",
11 "US-30"
12 ],
13 "street":"I-84",
14 "streetName":"I-84",
15 "speedLimit":"55.00MPH",
16 "countryCode":"US",
17 "countrySubdivision":"OR",
18 "countrySecondarySubdivision":"Multnomah",
19 "municipality":"Portland",
20 "postalCode":"97213",
21 "country":"United States Of America",
22 "countryCodeISO3":"USA",
23 "freeformAddress":"I-84, Portland, OR 97213",
24 "countrySubdivisionName":"Oregon"
25 },
26 "position":"45.531806,-122.596331"
27 }
28 ]

Fig. 11 Response with Speed Limit Information

We can also pass in configuration parameters for the vehicle, such as:

  • Vehicle Engine Type

  • Consumption Information - collection of pairs of speed and the corresponding consumption rate.

  • Acceleration and Deceleration Efficiency

  • Vehicle Metrics - Weight, Load Type, Max Speed

With these configuration parameters, the API returns information about expected fuel consumption. You can learn about these parameters in the Routing API Documentation.

You can also add the vehicle configuration for more accurate route planning. Routes can be decided based on speed, distance or eco mode. Eco mode factors in fuel consumption, vehicle efficiency, traffic, and hilliness of the route to find the route which consumes the least fuel/energy possible.

Additional Information

If you would like to learn more about options available within the TomTom APIs, you can access the online documentation or use the API Explorer to try different parameters and see how they all work together.

Having trouble leveraging location data points into actionable items for your customers?

The TomTom Search and Routing APIs and the TomTom Web and Mobile SDKs all have functionalities that allow the user to track a vehicle's current location and the route traveled, as well as obtain additional information such as speed limit parameters, expected fuel consumption data, and more. If you're looking for creative and comprehensive solutions for your customers, get in touch with us today for a free consultation.

Get the developer

No marketing fuff. Tech content only.
Thanks for contacting us

We will reach out to you soon.
Blog cards
tomtom tech news