here-api

Here.com Route API - V8 - State Mileage


We're trying to migrate from routes v7 to routes v8. Using v8, how can we get a breakdown of miles per US State?

In version 7.2 we could do

https://route.ls.hereapi.com/routing/7.2/calculateroute.json?apiKey=API_KEY&mode=fastest;truck&excludecountries=MEX,CAN&metricSystem=imperial&routeattributes=sm,sc&instructionFormat=text&truckType=tractorTruck&trailersCount=1&waypoint0=geo!33.90251,-81.13206&waypoint1=geo!39.80203,-105.08759

And the state codes would be in the summaryByCountry element:

"summaryByCountry": [
    {
        "distance": 189887,
        "trafficTime": 8239,
        "baseTime": 8206,
        "flags": [
            "motorway",
            "builtUpArea"
        ],
        "text": "The trip takes 118 mi and 2:17 h.",
        "travelTime": 8206,
        "country": "South Carolina",
        "_type": "RouteSummaryByCountryType"
    },
...
               

In version 8, a similar request:

https://router.hereapi.com/v8/routes?apiKey=API_KEY&origin=32.20618,-110.96474&destination=40.391537,-104.681168&routingMode=fast&transportMode=truck&avoid[features]=ferry&exclude[countries]=MEX,CAN&units=imperial&return=polyline,summary,actions,instructions&spans=countryCode,length,truckAttributes,notices&truck[trailerCount]=1&via=40.014984,-105.270546

"spans": [
    {
        "offset": 0,
        "truckAttributes": [
            "open"
        ],
        "length": 1460740,
        "countryCode": "USA"
    },
    {
        "offset": 14050,
        "truckAttributes": [
            "open",
            "tollRoad"
        ],
        "length": 272,
        "countryCode": "USA"
    },
    {
        "offset": 14053,
        "truckAttributes": [
            "open"
        ],
        "length": 23153,
        "countryCode": "USA"
    }

Solution

  • v7: summaryByCountry
    v8: Not present. If spans are requested with spans=countryCode,length, then information about the distance in each country can be retrieved. No plans to support in any other manner. Response in v8 contains :

    spans": [
                        {
                            "offset": 0,
                            "truckAttributes": [
                                "open"
                            ],
                            "length": 76817,
                            "countryCode": "USA"
                        }
                    ],
    

    link to migration guide : https://developer.here.com/documentation/routing-api/migration_guide/index.html