How to optimize a car route by traffic information

The user is looking for the fastest route from the central station in Wiesbaden, Germany, to the central station in Mainz, Germany, passing through the central stations in Frankfurt, Darmstadt, Hanau, and the airport in Frankfurt. The user needs the traffic information and wants to find a time-optimized route.

Request

curl -H "Authorization: Bearer BEARER_TOKEN" "https://wps.hereapi.com/v8/findsequence2?start=WiesbadenCentralStation;50.0715,8.2434&destination1=FranfurtCentralStation;50.1073,8.6647&destination2=DarmstadtCentralStation;49.8728,8.6326&destination3=FrankfurtAirport;50.0505,8.5698&destination4=HanauCentralStation;50.1218,8.9298&end=MainzCentralStation;50.0021,8.259&improveFor=time&departure=2014-12-09T09:30:00%2b01:00&mode=fastest;car;traffic:enabled"

Request using POST

GET requests are subject to request-line length limits imposed by load balancers. When optimizing a large number of waypoints, use POST and send the start point and the destinations in an application/x-www-form-urlencoded request body. Authentication and basic configuration parameters (such as mode, improveFor, and departure) remain in the query string.

curl -X POST 'https://wps.hereapi.com/v8/findsequence2?improveFor=time&departure=2014-12-09T09:30:00%2b01:00&mode=fastest;car;traffic:enabled&apikey=API_KEY' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  --data-raw 'start=WiesbadenCentralStation;50.0715,8.2434&destination1=FranfurtCentralStation;50.1073,8.6647&destination2=DarmstadtCentralStation;49.8728,8.6326&destination3=FrankfurtAirport;50.0505,8.5698&destination4=HanauCentralStation;50.1218,8.9298&end=MainzCentralStation;50.0021,8.259'

For very large requests, you can place the body in a file and send it with --data @findsequence2.txt.

Response

{
  "results": [
    {
      "waypoints": [
        {
          "id": "WiesbadenCentralStation",
          "lat": 50.0715,
          "lng": 8.2434,
          "sequence": 0,
          "estimatedArrival": null,
          "estimatedDeparture": "2014-12-09T09:30:00+01:00",
          "fulfilledConstraints": []
        },
        {
          "id": "FrankfurtAirport",
          "lat": 50.0505,
          "lng": 8.5698,
          "sequence": 1,
          "estimatedArrival": "2014-12-09T09:48:14+01:00",
          "estimatedDeparture": "2014-12-09T09:48:14+01:00",
          "fulfilledConstraints": []
        },
        {
          "id": "FranfurtCentralStation",
          "lat": 50.1073,
          "lng": 8.6647,
          "sequence": 2,
          "estimatedArrival": "2014-12-09T10:01:58+01:00",
          "estimatedDeparture": "2014-12-09T10:01:58+01:00",
          "fulfilledConstraints": []
        },
        {
          "id": "HanauCentralStation",
          "lat": 50.1218,
          "lng": 8.9298,
          "sequence": 3,
          "estimatedArrival": "2014-12-09T10:26:46+01:00",
          "estimatedDeparture": "2014-12-09T10:26:46+01:00",
          "fulfilledConstraints": []
        },
        {
          "id": "DarmstadtCentralStation",
          "lat": 49.8728,
          "lng": 8.6326,
          "sequence": 4,
          "estimatedArrival": "2014-12-09T10:59:54+01:00",
          "estimatedDeparture": "2014-12-09T10:59:54+01:00",
          "fulfilledConstraints": []
        },
        {
          "id": "MainzCentralStation",
          "lat": 50.0021,
          "lng": 8.259,
          "sequence": 5,
          "estimatedArrival": "2014-12-09T11:29:11+01:00",
          "estimatedDeparture": null,
          "fulfilledConstraints": []
        }
      ],
      "distance": "164286",
      "time": "7151",
      "interconnections": [
        {
          "fromWaypoint": "WiesbadenCentralStation",
          "toWaypoint": "FrankfurtAirport",
          "distance": 26628,
          "time": 1094,
          "rest": 0,
          "waiting": 0
        },
        {
          "fromWaypoint": "FrankfurtAirport",
          "toWaypoint": "FranfurtCentralStation",
          "distance": 15082,
          "time": 824,
          "rest": 0,
          "waiting": 0
        },
        {
          "fromWaypoint": "FranfurtCentralStation",
          "toWaypoint": "HanauCentralStation",
          "distance": 34647,
          "time": 1488,
          "rest": 0,
          "waiting": 0
        },
        {
          "fromWaypoint": "HanauCentralStation",
          "toWaypoint": "DarmstadtCentralStation",
          "distance": 49219,
          "time": 1988,
          "rest": 0,
          "waiting": 0
        },
        {
          "fromWaypoint": "DarmstadtCentralStation",
          "toWaypoint": "MainzCentralStation",
          "distance": 38710,
          "time": 1757,
          "rest": 0,
          "waiting": 0
        }
      ],
      "description": "Targeted best time; with , improvement for traffic",
      "timeBreakdown": {
        "driving": 7151,
        "service": 0,
        "rest": 0,
        "waiting": 0,
        "break": 0
      }
    }
  ],
  "errors": [],
  "processingTimeDesc": "123ms",
  "responseCode": "200",
  "warnings": null,
  "requestId": "3fc6f092-668f-4052-8514-c4aee94b3a08"
}

Did this page help you?