Python和openrouteservice在两个地理位置之间的行驶距离(并非所有地理位置都可以到达)

2024-09-26 18:10:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我的目标是获得两个地理位置(纬度和经度)之间的行驶距离/时间,这样做是为了一个大约2k对地理位置的文件。 我必须使用免费API或任何免费资源,这就是我使用openrouteservice的原因,在函数中包含以下简单代码,以获取行驶距离/时间:

import numpy as np
import pandas as pd
import openrouteservice
from openrouteservice import convert

api_key = 'api_key'
client = openrouteservice.Client(key=api_key)

coords = ((lon_orig, lat_orig),(lon_dest, lat_dest))
res = client.directions(coords, radiuses =1000)
res['routes'][0]['summary']

我的问题是由于这个API给出了类型为:'404 ({'error': {'code': 2009, 'message': 'Route could not be found - Unable to find a route between points...'的错误,因为并非所有的目的地地理位置对都可以通过驾驶或步行到达

举个例子,当我尝试coords = ((-69.20438,-12.58308),(-70.43474,-13.03910))时,我得到了一个错误,因为那里像一条河,所以汽车无法到达确切的点

因此,我想知道是否有某种方法可以将目的地地理位置近似为某种新的可到达位置(我阅读了openrouteservice文档,但没有找到类似的内容,还试图增加“radius”参数,但我还是出错了),或者可能使用另一个API来帮助openrouteservice改进这一点,或者最后推荐另一种有效的方法


Tags: keyimportclientapi距离asservice时间

热门问题