How get total distance and time from waypoints in HERE REST API

232 views Asked by At

I need to get the total distance and time from waypoints in HERE REST API. Now i use the routing api:

https://route.api.here.com/routing/7.2/calculateroute.json
"app_id="           + API_ID
"&app_code="        + APP_CODE
"&waypoint0=geo!"   + fromCoordsLocation
"&waypoint1=geo!"   + toCoordsLocation
"&mode=fastest;car"

and read them from json summary object (Response->Route->Summary). This method returns all the maneuvers and for long distances the callback is slow. there is something that allows only the summary (or the total distance and time) to be received?

1

There are 1 answers

0
Tấn Nguyên On BEST ANSWER

Check out these additional properties so you can customize the request as you want. In this case I used representation = overview, your request will be

https://route.api.here.com/routing/7.2/calculateroute.json
"app_id="           + API_ID
"&app_code="        + APP_CODE
"&waypoint0=geo!"   + fromCoordsLocation
"&waypoint1=geo!"   + toCoordsLocation
"&mode=fastest;car&representation=overview"

The response will be decreased to 78 lines with default 232 lines:

{
    "response": {
        "metaInfo": {
            "timestamp": "2019-11-14T10:03:16Z",
            "mapVersion": "8.30.102.151",
            "moduleVersion": "7.2.201945-5699",
            "interfaceVersion": "2.6.74",
            "availableMapVersion": [
                "8.30.102.151"
            ]
        },
        "route": [
            {
                "waypoint": [
                    {
                        "linkId": "-53623477",
                        "mappedPosition": {
                            "latitude": 52.4999825,
                            "longitude": 13.3999652
                        },
                        "originalPosition": {
                            "latitude": 52.5,
                            "longitude": 13.4
                        },
                        "type": "stopOver",
                        "spot": 0.3538462,
                        "sideOfStreet": "left",
                        "mappedRoadName": "Neuenburger Straße",
                        "label": "Neuenburger Straße",
                        "shapeIndex": 0,
                        "source": "user"
                    },
                    {
                        "linkId": "+1215312511",
                        "mappedPosition": {
                            "latitude": 52.4992955,
                            "longitude": 13.4491968
                        },
                        "originalPosition": {
                            "latitude": 52.5,
                            "longitude": 13.45
                        },
                        "type": "stopOver",
                        "spot": 1.0,
                        "sideOfStreet": "left",
                        "mappedRoadName": "Schlesische Straße",
                        "label": "Schlesische Straße",
                        "shapeIndex": 56,
                        "source": "user"
                    }
                ],
                "mode": {
                    "type": "fastest",
                    "transportModes": [
                        "car"
                    ],
                    "trafficMode": "disabled",
                    "feature": []
                },
                "summary": {
                    "distance": 3847,
                    "trafficTime": 869,
                    "baseTime": 667,
                    "flags": [
                        "noThroughRoad",
                        "builtUpArea",
                        "park",
                        "privateRoad"
                    ],
                    "text": "The trip takes <span class=\"length\">3.8 km</span> and <span class=\"time\">11 mins</span>.",
                    "travelTime": 667,
                    "_type": "RouteSummaryType"
                }
            }
        ],
        "language": "en-us"
    }
}