Distance between more than 2 point

I used route[‘features’][0][‘properties’][‘segments’][0][‘distance’] to get the distance of three consecutive points but I only got distance between first and second point only.

coordinates = [[lon,lat],[lon,lat],[lon,lat]]
route = client.directions(coordinates = coordinates, profile = ‘driving-car’, format = ‘geojson’)
distance = route[‘features’][0][‘properties’][‘segments’][0][‘distance’]

how can I get the whole distance?

Hey,

as noted in this post, this again is not valid python syntax, since profile, format and the features, properties, segments and distance key in route are strings and thus should be enclosed in matching single or double quotes, not backticks.

Note, that this is easier to see when pasting code using the syntax formatting provided by discourse, which is done by enclosing text in 3 backticks (```), which will format it as a code block or enclosing text in 1 backtick (`), which will format it inline.

For a documentation of your route-geojson, refer to the documentation of route in the response tab of the documentation of the default directions endpoint (click on the green questionmark). Disregard any keys not present in your response.

When asking for a route using more than two coordinates, every pair of coordinates defines a segment, i.e. the route between these two coordinates.

Best regards,
Jakob

Jakob,
I finally got the whole distance after you said to refer my geojson route. I am really grateful.
But now I don’t understand the backticks and quotes that you mentioned. So which one is the real python syntax, backticks(`) or quotes(’)?
The docs.python link you shared does not mention anything about backticks and I did not type down any backticks character in my post. So I am confused right now😅. Please help me understand the problem, I am currently a student and new to python.
Thank you.
Best regards,
Izzat

1 Like

Hey,

I’m glad that you figured out the geojson response :))

Regarding backticks: yes, I misread :frowning:
They aren’t backticks, but opening (U+2018) and closing (U+2019) single quotation marks.

If I try this code snippet in python, I get a fitting

SyntaxError: invalid character '‘' (U+2018)

What you are looking for is ' (Ascii 39, Apostrophe) or " (Ascii 22, Quotation Mark).
These are the characters used in the python docs.

Sorry for causing confusion,
Best regards,
Jakob

Now I get it. The (') converted to (’) when I paste the code here. So I need to use backtick to keep the format. This is my first time knowing such detail and how both are different. Thank you so much for the knowledge.

1 Like