Getting a distance

Hello!

Probably a silly question. I just want to get the distance between two points using openrouteservice in python.

I have tried to extract the distance using:

import openrouteservice as ors

client = ors.Client(key='xxx')


coords = ((8.34234,48.23424),(8.34423,48.26424))


routes = client.directions(coords)

print (routes['summary'[1]])

I’ve tried several other combinations, but i’m finding it hard to extract.

Please let me know what the correct way to simply print the distance would be? It should just be a number like : 5541.5

Cheers!

Well, that’s not valid Python syntax… print (routes[‘summary’[1]]). also pleeease use code formatting i.e. backticks. Maybe just a typo.

Apart from that, I think you should find out stuff like this by yourself. Just inspect the response, it’s just a dictionary, won’t be hard to find out where the summary is hidden.

ah solved it. Thank you

If you don’t know how:

enclosing text in 3 ``` will format as code block, enclosing with 1 backtick ``will do inline code.

try a print(routes), you really should be able to take it yourself from there on.

Execuse me, could you please give me your solution. I have been wondering the answer.

Hi @Letsplay-github,

you can either check the response object itself or from e.g. our api documentation for the response structure:

from there it is basic python dictionary/array access:
routes[0]['summary']['distance']

Hi @amandus,
I finally got the distance, and I am surprise that there is so much more I can get from the documentation response. This is a really big help(currently doing my university assignment). Thank you so much.
Best regards
Izzat