我如何计算乘车时间?
how can i calculate the length of a car ride?
我必须计算两个地址(例如“Milano, Piazza Duomo”和“Roma, Piazza”)之间的车程(不是乌鸦飞的距离)纳沃纳”)在 Python。我该怎么做?
我看了geopy的文档,但是没有解决任何问题
def get_distance(point1: dict, point2: dict) -> tuple:
"""Gets distance between two points en route using http://project-osrm.org/docs/v5.10.0/api/#nearest-service"""
url = f"""http://router.project-osrm.org/route/v1/driving/{point1["lon"]},{point1["lat"]};{point2["lon"]},{point2["lat"]}?overview=false&alternatives=false"""
r = requests.get(url)
# get the distance from the returned values
route = json.loads(r.content)["routes"][0]
return (route["distance"], route["duration"])
我必须计算两个地址(例如“Milano, Piazza Duomo”和“Roma, Piazza”)之间的车程(不是乌鸦飞的距离)纳沃纳”)在 Python。我该怎么做?
我看了geopy的文档,但是没有解决任何问题
def get_distance(point1: dict, point2: dict) -> tuple:
"""Gets distance between two points en route using http://project-osrm.org/docs/v5.10.0/api/#nearest-service"""
url = f"""http://router.project-osrm.org/route/v1/driving/{point1["lon"]},{point1["lat"]};{point2["lon"]},{point2["lat"]}?overview=false&alternatives=false"""
r = requests.get(url)
# get the distance from the returned values
route = json.loads(r.content)["routes"][0]
return (route["distance"], route["duration"])