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"])
相关问题 更多 >
编程相关推荐