5

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.

Karthik Katragadda
  • 176
  • 1
  • 2
  • 11

1 Answers1

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