Adding EV Routing to a TomTom Web Map: Understanding the APIs
TomTom Developer Portal·May 28, 2020

Adding EV Routing to a TomTom Web Map: Understanding the APIs

TomTom Developer Portal
TomTom Developer Portal
May 28, 2020 · 9 min read

By 2040, more than half of all vehicles sold are expected to be electric. But today, Electric vehicle (EV) owners often struggle to plan trips that ensure timely and convenient access to charging facilities. In this article, the first part of a series, we'll explore how developers can use the EV Routing Service to easily create engaging and helpful applications that help EV owners plan travel routes that include charging stops.

By the year 2040, 57% of passenger vehicles sold will be electric, according to a recent BloombergNEF report (Source: BloombergNEF). Today, consumers continue to struggle to plan trips that ensure timely and convenient access to charging facilities — due in large part to navigation software that lacks the routing services needed by electric vehicle (EV) drivers.

Thankfully, TomTom is helping EV owners avoid "range anxiety" with its award-winning Long-Distance EV Routing service. In this two-part article, we'll explore how developers can use the EV Routing service to easily create engaging and helpful applications for consumers. We’ll start in Part 1 with a look at the relevant APIs, and explore information particular to EVs. In Part 2, we’ll build an app that allows the user to specify a starting and finishing location, calculate a route between these endpoints, and display both the route and charging stops along the way.

To use TomTom's services, you’ll need to obtain an API key that authorizes their use. In the code and URLs that follow, just be sure to replace "YOUR_API_KEY" with the TomTom API Key you obtained.

You should also log in to the TomTom developer dashboard, edit your application, and make certain that all of the necessary TomTom products (such as the Search API and Extended Search API) are checked.

Now let’s look at the various APIs we’ll use to create the app.

Search API

In order to use the TomTom Routing API or the Long Distance EV Routing service, the unique starting and ending locations the route will connect are required. The Search API provides a powerful mechanism for turning a user's colloquial input (for example, Los Angeles) into a unique location (such as latitude 34.05224 and longitude -118.24334).

That mechanism is TomTom's Fuzzy Search service. To search for "Los Angeles" you can make a simple web request to the following URL:


The response would appear as follows, with the "position" property of the first result providing the latitude and longitude of the city.

2  "summary": {
3    "query": "los angeles",
4    "queryType": "NON_NEAR",
5    "queryTime": 47,
6    "numResults": 10,
7    "offset": 0,
8    "totalResults": 28490,
9    "fuzzyLevel": 1
10  },
11  "results": [
12    {
13      "type": "Geography",
14      "id": "US/GEO/p0/355711",
15      "score": 5.90292,
16      "entityType": "Municipality",
17      "address": {
18        "municipality": "Los Angeles",
19        "countrySecondarySubdivision": "Los Angeles",
20        "countryTertiarySubdivision": "Los Angeles",
21        "countrySubdivision": "CA",
22        "countryCode": "US",
23        "country": "United States",
24        "countryCodeISO3": "USA",
25        "freeformAddress": "Los Angeles, CA",
26        "countrySubdivisionName": "California"
27      },
28      "position": {
29        "lat": 34.05224,
30        "lon": -118.24334
31      },
32      "viewport": {
33        "topLeftPoint": {
34          "lat": 34.33673,
35          "lon": -118.6684
36        },
37        "btmRightPoint": {
38          "lat": 33.70366,
39          "lon": -118.15541
40        }
41      },
42      "boundingBox": {
43        "topLeftPoint": {
44          "lat": 34.33673,
45          "lon": -118.6684
46        },
47        "btmRightPoint": {
48          "lat": 33.70366,
49          "lon": -118.15541
50        }
51      },
52      "dataSources": {
53        "geometry": {
54          "id": "00005543-3600-3c00-0000-00005a3f4260"
55        }
56      }
57    },
58    .
59    .
60    .
61  ]

For web developers, TomTom also offers a Web SDK to simplify interaction with its APIs. This API provides a simple-to-call function for most services. These functions typically format the URL, issue the web request, fetch and parse the response, and return a JavaScript promise with which you can interact.

For example, the following function call is equivalent to the earlier Fuzzy Search example. If the web request succeeds, the JavaScript promise’s “then” function is called with a simple object containing the response; otherwise, its “catch” function is called with information describing the error.{ key: 'YOUR_API_KEY', query:  'Los Angeles' })
2  .go()
3  .then(function(response) {
4    console.log('Success!');
5    console.log(response);
6  })
7  .catch(function(error) {
8    console.log('Error!');
9    console.log(error);
10  });

Routing API

TomTom offers a Routing API that calculates a route between two endpoints. The Routing API takes real-time traffic information and weather incidents into account to help consumers avoid delays. This powerful API now includes the Long-Distance EV Routing service, which allows consumers to provide detailed information about their electric vehicles and get a route specifically calculated to ensure that charging stations are available along the way.

To use the service, you’ll need to understand basic information that may be necessary when creating apps for electric vehicles. Unfortunately, the information provided by automobile manufacturers and reviewers often includes abbreviations that are used with little or no explanation. In the table below, you'll find a glossary of some common abbreviations used in the description of electric vehicles.

| Abbr | Meaning | Description | | A | Amperes | Amperage is a measure of electric current — the quantity of electric charge moving across a circuit in a given period of time. Using plumbing as an analogy, it’s similar to flow rate. | | V | Volts | Voltage is a measure of electromotive force. It measures the force driving the electric charge across a circuit. Again, using plumbing as an analogy, it’s similar to water pressure. | | AC | Alternating Current | With alternating current, electric current alternates directions at regular intervals. When you plug something in at home or at work, power is delivered via alternating current. | | DC | Direct Current | With direct current, electric current flows in a single direction. Battery-operated devices run on direct current. In truth, most devices run on direct current. Plug-in devices simply take an extra step, first converting the alternating current from your wall plug into the direct current they require. | | W | Watts | Wattage is a measure of the total power. It’s calculated quite easily by multiplying voltage by amperage (W = V x A). | | kW | Kilowatts | One kilowatt is a thousand watts (kW = W / 1000). | | kWh | Kilowatt Hours | A kilowatt-hour is a measure of power over time. For example, 1 kilowatt-hour could deliver a single kilowatt of power for an entire hour, 500 watts for two hours, or 1 watt for 1,000 hours. | | SoC | State of Charge | The state of charge (SoC) is a measure of the percentage of charge in a battery, ranging from 0 (empty) to 1 (full). For example, an SoC of 0.5 would indicate that a battery is at 50%. | | PEV | Plug-in Electric Vehicle | A plug-in electric vehicle is any vehicle that can be plugged in to charge the battery. It includes both battery-electric vehicles (BEV) and plug-in hybrid electric vehicles (PHEV). | | BEV | Battery Electric Vehicle | A battery-electric vehicle runs entirely on battery power. It does not use gasoline. | | PHEV | Plug-in Hybrid Electric Vehicle | A plug-in hybrid electric vehicle runs on either battery power or gasoline. It can be refueled either by adding gasoline or by plugging in to recharge the battery. |

There are also a number of parameters used as inputs to the service. The first is the consumption model, which describes the battery capacity of the vehicle, how quickly it discharges, and how it behaves under various driving conditions (such as acceleration).

Another set of inputs to this service describes the charging model — the different modes of charging supported by the electric vehicle. This includes the type of plug (or connector), the type of electrical facility, and the rate at which the vehicle will charge when a particular combination of plug and facility is used. Thankfully, TomTom has provided a very flexible model for specifying this information that accommodates virtually any vehicle. Here’s a bit more detail:

  • The plug type describes the physical connection between the car and the charging station. While some common plug types are emerging (such as SAE J1772), there remains a patchwork of different connectors that often depend on automobile manufacturer or geographical location.

  • The facility type describes the electrical characteristics of the port at the charging station. A single plug may allow a connection with different ports, each with different electrical characteristics, including the type of current (alternating or direct), the voltage (120V or 240V), the amperage (12A or 20A), and (for AC connections) the number of phases (1 or 3).

  • The charging curve describes how a particular vehicle will charge at a facility, given its specific characteristics. The rate at which batteries charge depends principally on the facility type and the unique charging circuitry of the vehicle. However, batteries don’t necessarily charge in a linear fashion. They generally charge more quickly when empty and less quickly as they approach a full charge.

To provide accurate estimates of charging times, the TomTom API lets you use the unique charging curve of the vehicle when connected to a specific pairing of plug type and facility type.

Using the Long-Distance EV Routing Service

The Long Distance EV Routing service calculates a route between an origin and a destination that includes charging stops. The consumption model and many other parameters are passed as simple query string parameters in the URL for the web request.

For example, when accompanied by a POST body that specifies charging modes, the URL below calculates the route between Boston (latitude 42.35899, longitude -71.05863) and Washington D.C. (latitude 38.89206, longitude -77.01991), making certain that the route includes charging stops so that the remaining battery charge never drops below 20 kWh. The consumption model specifies an electric vehicle that’s fully charged to its maximum capacity of 100 kWh. It further indicates that when traveling at a constant speed of 100 km/h, the vehicle will consume 20 kWh of battery charge for every 100 kilometers of travel.


The charging modes are passed in the body of a POST web request. The example below uses an SAE J1772 plug that can be connected to a single-phase alternating current at 200-240 volts, at 32 amperes or above. When connected, the vehicle will charge to 80kWh in 25,000 seconds, reaching a full charge of 100kWh in 50,000 seconds.

2  "chargingModes": [
3    {
4      "chargingConnections": [
5        {
6          "facilityType": "Charge_200_to_240V_1_Phase_at_32A",
7          "plugType": "SAE_J1772"
8        },
9        {
10          "facilityType": "Charge_200_to_240V_1_Phase_above_32A",
11          "plugType": "SAE_J1772"
12        }
13      ],
14      "chargingCurve": [
15        {
16          "chargeInkWh": 80,
17          "timeToChargeInSeconds": 25000
18        },
19        {
20          "chargeInkWh": 100,
21          "timeToChargeInSeconds": 50000
22        }
23      ]
24    }
25  ]

A successful response includes a route summary, the legs of the route, a summary of each leg, and the points (latitude and longitude) that make up that leg. The route is broken up into legs so that each charging stop can be represented. The charging stop (or destination) appears as the final point in each route leg. Here’s an excerpt from an example response:

2  "formatVersion": "0.0.12",
3  "routes": [
4    {
5      "summary": {
6        "lengthInMeters": 713569,
7        "travelTimeInSeconds": 64578,
8        "trafficDelayInSeconds": 0,
9        "departureTime": "2019-10-14T09:16:54-04:00",
10        "arrivalTime": "2019-10-15T03:13:12-04:00",
11        "batteryConsumptionInkWh": 142.71380000000002,
12        "remainingChargeAtArrivalInkWh": 21.01679999999999,
13        "totalChargingTimeInSeconds": 39266
14      },
15      "legs": [
16        {
17          "summary": {
18            "lengthInMeters": 318653,
19            "travelTimeInSeconds": 11640,
20            "trafficDelayInSeconds": 0,
21            "departureTime": "2019-10-14T09:16:54-04:00",
22            "arrivalTime": "2019-10-14T12:30:54-04:00",
23            "batteryConsumptionInkWh": 63.7306,
24            "remainingChargeAtArrivalInkWh": 36.2694,
25            "chargingInformationAtEndOfLeg": {
26              "targetChargeInkWh": 100,
27              "chargingTimeInSeconds": 39266,
28              "chargingConnections": [
29                {
30                  "facilityType": "Charge_200_to_240V_1_Phase_at_32A",
31                  "plugType": "SAE_J1772"
32                }
33              ],
34              "chargingParkUuid": "2cfb40b9-66ed-3afd-4a01-b5ba00153b86"
35            }
36          },
37          "points": [
38            {
39              "latitude": 42.35899,
40              "longitude": -71.05864
41            },
42            ...

In this article, we’ve looked at the TomTom Long Distance EV Routing service and discussed what you need to know to create an application that uses the service to supply routing and charging information to electric vehicle users.

In part two of this article, we’ll create an app that lets users specify a starting and ending point, calculates a route between them, and shows charging stops along the route.

To get started with what was covered in this article and learn more about some of TomTom's products, check out some of the links below:

Happy coding!

Get the developer newsletter.
No marketing fuff. Tech content only.

* Required field. By submitting your contact details to TomTom, you agree that we can contact you about marketing offers, newsletters, or to invite you to webinars and events. We could further personalize the content that you receive via cookies. You can unsubscribe at any time by the link included in our emails. Review our privacy policy.