Getting a distance


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


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.