I want to get the driving distance between two points in python. I am not allowed to use Google Maps API. Are there any open source APIs that help to calculate the driving distance between two points? If yes, a small example is Python will be amazing. Thanks in advance.
Asked
Active
Viewed 1.3k times
5
-
https://wiki.openstreetmap.org/wiki/Routing#End_users:_Routing_software – scai Mar 14 '19 at 14:10
1 Answers
17
Example from the python package OSMNX:
example doc -> routing
import networkx as nx
import osmnx as ox
# get the nearest network node to each point
orig_node = ox.get_nearest_node(G, (37.828903, -122.245846))
dest_node = ox.get_nearest_node(G, (37.812303, -122.215006))
# how long is our route in meters?
nx.shortest_path_length(G, orig_node, dest_node, weight='length')
Documentation on how to install: https://osmnx.readthedocs.io/en/stable/#installation
Note the following excerpt:
'If you are pip installing OSMnx, install geopandas and rtree first. It’s easiest to use conda-forge to get these dependencies installed.'

Joery
- 346
- 1
- 5
-
you need to add this line to answer `G = ox.graph_from_place("ADDRESS", network_type="drive")` – mallet Feb 22 '23 at 14:46