如何使用Python获取两个地理坐标之间的驾车距离?

5

我想在Python中获取两点之间的驾车路程。不允许使用Google Maps API。是否有任何开源API可以帮助计算两个点之间的驾车路程?如果是,一个小的Python示例将是惊人的。提前致谢。


https://wiki.openstreetmap.org/wiki/Routing#End_users:_Routing_software - scai
1个回答

17

Python包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

请注意以下摘录:

'如果您正在使用pip安装OSMnx,请先安装geopandas和rtree。最简单的方法是使用conda-forge来安装这些依赖项。'


你需要将这行代码添加到答案中:G = ox.graph_from_place("ADDRESS", network_type="drive") - mallet

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接