Draw GPX data on map

Hello community! After downloading the GPX route data (ex: NC500) how can I draw this on the map?

You could convert GPX to geojson, which is easy to put on a map.
Here is an example library: @tmcw/togeojson - npm

Thank you for the fast reply. For future readers, you might be more interested in the following library: gpxparser - npm.

Hi Przemek,

I have been able to draw the route on the map. Now, how can I do the same but for EV routing instead? Is this possible?

Thank you in advance,

Hadi

There is an example with this case: Examples | Maps SDK for Web (v6) | TomTom Developer Portal

The example is great, however, it’s not what I was looking for exactly. The example you suggested calculates the route between 2 points. I want to instead provide the Long Distance EV Routing API call with a pre-defined route. This route could be a gpx file for example. Is this possible?

Route reconstruction with Long Distance EV Routing is not possible. It only allows to provide two points: origin and destination.

That’s what I thought. When looking at the example you provided me above, the following error pops up: “There was a problem calculating the route”. I’ve attached an image for illustration. I’ve also inspected the API call, using Chrome dev tools, for this example and I’ve found the following error:

{"formatVersion":"0.0.1","error":{"description":"Engine error while executing route request: NO_ROUTE_FOUND"},"detailedError":{"message":"Engine error while executing route request: NO_ROUTE_FOUND","code":"NO_ROUTE_FOUND"}}

The request URL, again taken from chrome dev tools, is the following:

https://api.tomtom.com/routing/1/calculateLongDistanceEVRoute/52.377956,4.897070:44.650232,10.886712/json?key=***&traffic=false&vehicleWeight=2200&uphillEfficiency=0.74&downhillEfficiency=0.73&constantSpeedConsumptionInkWhPerHundredkm=100%2C20.09&currentChargeInkWh=100&maxChargeInkWh=100&vehicleEngineType=electric&minChargeAtDestinationInkWh=2&minChargeAtChargingStopsInkWh=2

(I have removed the API key above because your website isn’t allowing me to post it.)

Is this problem only occurring on my machine or is it happening on yours too?

Thank you in advance for your help again.

We are still investigating this. This example was working, but now it is not.

Hi Przemek, I might have discovered something that is useful. If you try to replicate the same request with the same parameters and body in Postman, you’d get a valid response.

Request URL:

https://api.tomtom.com/routing/1/calculateLongDistanceEVRoute/57.478382790188604%2C-4.224799676312642%3A58.64031542690979%2C-3.072726594639203/json?key=***&traffic=false&vehicleWeight=2200&uphillEfficiency=0.74&downhillEfficiency=0.73&constantSpeedConsumptionInkWhPerHundredkm=100%2C20.09&currentChargeInkWh=100&maxChargeInkWh=100&vehicleEngineType=electric&minChargeAtDestinationInkWh=2&minChargeAtChargingStopsInkWh=2

Request Body (json):

{
    "chargingModes": [
        {
            "chargingConnections": [
                {
                    "facilityType": "Charge_200_to_480V_Direct_Current_at_255A_120kW",
                    "plugType": "Tesla_Connector"
                },
                {
                    "facilityType": "Charge_380_to_480V_3_Phase_at_63A",
                    "plugType": "Tesla_Connector"
                },
                {
                    "facilityType": "Charge_50_to_500V_Direct_Current_at_125A_50kW",
                    "plugType": "Tesla_Connector"
                },
                {
                    "facilityType": "Charge_50_to_500V_Direct_Current_at_62A_25kW",
                    "plugType": "Tesla_Connector"
                },
                {
                    "facilityType": "Charge_50_to_500V_Direct_Current_at_62A_25kW",
                    "plugType": "SAE_J1772"
                },
                {
                    "facilityType": "Charge_50_to_500V_Direct_Current_at_125A_50kW",
                    "plugType": "SAE_J1772"
                },
                {
                    "facilityType": "Charge_380_to_480V_3_Phase_at_63A",
                    "plugType": "SAE_J1772"
                },
                {
                    "facilityType": "Charge_380_to_480V_3_Phase_at_32A",
                    "plugType": "SAE_J1772"
                },
                {
                    "facilityType": "Charge_380_to_480V_3_Phase_at_16A",
                    "plugType": "SAE_J1772"
                }
            ],
            "chargingCurve": [
                {
                    "chargeInkWh": 50,
                    "timeToChargeInSeconds": 1200
                },
                {
                    "chargeInkWh": 80,
                    "timeToChargeInSeconds": 2400
                },
                {
                    "chargeInkWh": 100,
                    "timeToChargeInSeconds": 4500
                }
            ]
        },
        {
            "chargingConnections": [
                {
                    "facilityType": "Charge_380_to_480V_3_Phase_at_32A",
                    "plugType": "Tesla_Connector"
                },
                {
                    "facilityType": "Charge_100_to_120V_1_Phase_at_16A",
                    "plugType": "Tesla_Connector"
                },
                {
                    "facilityType": "Charge_200_to_240V_1_Phase_at_32A",
                    "plugType": "Tesla_Connector"
                },
                {
                    "facilityType": "Charge_200_to_240V_1_Phase_at_16A",
                    "plugType": "Tesla_Connector"
                },
                {
                    "facilityType": "Charge_200_to_240V_3_Phase_at_32A",
                    "plugType": "Tesla_Connector"
                },
                {
                    "facilityType": "Charge_200_to_240V_1_Phase_at_12A",
                    "plugType": "SAE_J1772"
                },
                {
                    "facilityType": "Charge_200_to_240V_1_Phase_at_32A",
                    "plugType": "SAE_J1772"
                },
                {
                    "facilityType": "Charge_200_to_240V_1_Phase_at_10A",
                    "plugType": "SAE_J1772"
                },
                {
                    "facilityType": "Charge_200_to_240V_3_Phase_at_32A",
                    "plugType": "SAE_J1772"
                },
                {
                    "facilityType": "Charge_200_to_240V_1_Phase_at_16A",
                    "plugType": "SAE_J1772"
                },
                {
                    "facilityType": "Charge_100_to_120V_1_Phase_at_16A",
                    "plugType": "SAE_J1772"
                }
            ],
            "chargingCurve": [
                {
                    "chargeInkWh": 100,
                    "timeToChargeInSeconds": 90000
                }
            ]
        }
    ]
}

Response

{
    "formatVersion": "0.0.12",
    "routes": [
        {
            "summary": {
                "lengthInMeters": 192221,
                "travelTimeInSeconds": 9375,
                "trafficDelayInSeconds": 117,
                "trafficLengthInMeters": 511,
                "departureTime": "2021-08-03T16:56:05+01:00",
                "arrivalTime": "2021-08-03T19:32:19+01:00",
                "batteryConsumptionInkWh": 44.807932400000006,
                "remainingChargeAtArrivalInkWh": 55.192067599999994
            },
            "legs": [
                {
                    "summary": {
                        "lengthInMeters": 192221,
                        "travelTimeInSeconds": 9375,
                        "trafficDelayInSeconds": 117,
                        "trafficLengthInMeters": 511,
                        "departureTime": "2021-08-03T16:56:05+01:00",
                        "arrivalTime": "2021-08-03T19:32:19+01:00",
                        "batteryConsumptionInkWh": 44.807932400000006,
                        "remainingChargeAtArrivalInkWh": 55.192067599999994
                    },
                    "points": []
                }
            ],
            "sections": [
                {
                    "startPointIndex": 0,
                    "endPointIndex": 3226,
                    "sectionType": "TRAVEL_MODE",
                    "travelMode": "car"
                }
            ]
        }
    ]
}

(In order to make my post concise, I didn’t copy over the points)

Hope this helps