0

I am trying to obtain the best route using FindSequence API for n number of destinations. Here is my code:

URL5 = "https://wse.ls.hereapi.com/2/findsequence.json"
params5 = {
    "apiKey": my_key,
    "departure":"2014-11-11T16:52:00Z",
    "start": first,
    "destinations": [i for i in f], 
    "end": last,
    "mode": "fastest;truck;traffic:enabled" # To enable traffic, "departure" parameter must be included
}

res5 = requests.get(url = URL5, params = params5)
data5 = res5.json()

Where first and last are strings with name of the destination;lat,long

  • first = "HARDIE'S MOBILE HOME PARK; 30.44126118, -86.6240656099999"
  • last = "HOUSTON PARK MOBILE HOME PARK; 30.4424195300001, -86.64733076"

And f is a list with the other points the route must pass before arriving to the last destination.

f = ['CRESTVIEW RV PARK; 30.7190163500001, -86.5716222299999',
 'HOMESTEAD TRAILER PARK; 30.5115772500001, -86.4628417499999']

However, it looks like it is just "reading" the first and last data points and is completely ignoring the other two destinations from the list f. This is the output I am getting:

[{'id': "HARDIE'S MOBILE HOME PARK",
  'lat': 30.44126118,
  'lng': -86.6240656099999,
  'sequence': 0,
  'estimatedArrival': None,
  'estimatedDeparture': '2014-11-11T16:52:00Z',
  'fulfilledConstraints': []},
 {'id': 'HOUSTON PARK MOBILE HOME PARK',
  'lat': 30.4424195300001,
  'lng': -86.64733076,
  'sequence': 1,
  'estimatedArrival': '2014-11-11T17:02:30Z',
  'estimatedDeparture': None,
  'fulfilledConstraints': []}]

The desired output must look like this:

[{'id': "HARDIE'S MOBILE HOME PARK",
  'lat': 30.44126118,
  'lng': -86.6240656099999,
  'sequence': 0,
  'estimatedArrival': None,
  'estimatedDeparture': '2014-11-11T16:52:00Z',
  'fulfilledConstraints': []},
 {'id': 'CRESTVIEW RV PARK',
  'lat': 30.719016,
  'lng': -86.571622,
  'sequence': 1,
  'estimatedArrival': None,
  'estimatedDeparture': '2014-11-11T17:37:08Z',
  'fulfilledConstraints': []},
 {'id': 'HOMESTEAD TRAILER PARK',
  'lat': 30.511577,
  'lng': -86.462842,
  'sequence': 2,
  'estimatedArrival': None,
  'estimatedDeparture': '2014-11-11T18:07:25Z',
  'fulfilledConstraints': []},
 {'id': 'HOUSTON PARK MOBILE HOME PARK',
  'lat': 30.4424195300001,
  'lng': -86.64733076,
  'sequence': 3,
  'estimatedArrival': '2014-11-11T18:43:24Z',
  'estimatedDeparture': None,
  'fulfilledConstraints': []}]

And that desired output can be obtained using this code:

URL3 = "https://wse.ls.hereapi.com/2/findsequence.json"
params3 = {
    "apiKey": here_api_key,
    "departure":"2014-11-11T16:52:00Z",
    "start": first,
    "destination1": "CRESTVIEW RV PARK;30.719016, -86.571622",
    "destination2": "HOMESTEAD TRAILER PARK;30.511577, -86.462842",
    "end": last,
    "mode": "fastest;truck;traffic:enabled" # To enable traffic, "departure" parameter must be included
}

res3 = requests.get(url = URL3, params = params3)
data3 = res3.json()

Although the code above works just fine, it is not the best approach since I need to pass from than just 2 destinations. I am new at HERE APIs so If anyone knows how to do that I would really appreciate your help!

brenda
  • 656
  • 8
  • 24

1 Answers1

0

You can verify in the FindSequence API documentation there is no such thing as a destinations parameter, so it is totally understandable that in your 1st example the route does not visit these destinations. So you must pass destination1, destination2 etc parameters.

If you want to automatically create these parameters in your Dictionary, as I am not a Python user, please search in StackOverflow to find out how, that are many answers that can help you, for example:

programmatically generate key and values to put in python dictionary

Create dictionary where keys are variable names

psxls
  • 6,807
  • 6
  • 30
  • 50