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.
How to get the driving distance between two geographical coordinates using python?
Asked Answered
wiki.openstreetmap.org/wiki/Routing#End_users:_Routing_software –
Sonni
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.'
you need to add this line to answer
G = ox.graph_from_place("ADDRESS", network_type="drive")
–
Malherbe © 2022 - 2024 — McMap. All rights reserved.