如何使用python获取两个地理坐标之间的行驶距离?
问题描述:
我想获取python中两点之间的行驶距离.我不允许使用Google Maps API.是否有任何开源API可以帮助计算两点之间的行驶距离?如果是,那么一个小例子就是Python将会很棒.提前致谢.
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.
答
python软件包OSMNX中的示例:
Example from the python package OSMNX:
示例文档 ->路由
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')
有关如何安装的文档: https://osmnx.readthedocs.io/en/stable /#installation
Documentation on how to install: https://osmnx.readthedocs.io/en/stable/#installation
请注意以下摘录:
'如果要点点安装OSMnx,请先安装geopandas和rtree.使用conda-forge来安装这些依赖项是最简单的.'