根据 OSRMRoadManager 中的 API 密钥创建 URL
我已在 openrouteservice.org 上注册了 API。如何将其导入 OSRMRoadManager?我已经尝试了 网站,但我的每次尝试都会导致 403 错误,并带有注释 org.json.JSONException: No value for code
以及指向以下内容的链接:(
{
"error": "Daily quota reached or API key unauthorized"
}
我没有使用过该错误之前有API,所以我无法用完配额。密钥是有效的,因为我已经使用上述网站的链接对其进行了测试)
我的 Kotlin 代码(在我最近的尝试中)如下([MY_API_KEY] 显然正在替换我的真实密钥) ):
val roadManager = OSRMRoadManager(context, context?.packageName)
(roadManager as OSRMRoadManager).setService("https://api.openrouteservice.org/v2/directions/driving-car/geojson?api_key=[MY_API_KEY]")
val waypoints = ArrayList<GeoPoint>()
waypoints.add(GeoPoint(lastLocLat, lastLocLong)) //last known location
val endPoint = GeoPoint(randomOverlay.getItem(0).point.latitude, randomOverlay.getItem(0).point.longitude) //destination
waypoints.add(endPoint)
val road = roadManager.getRoad(waypoints)
我的猜测是,路径点坐标应该以不同的方式包含在链接中,但我不知道如何改变它。
I've signed up for an API on openrouteservice.org. How do I import it into OSRMRoadManager? I've tried all the combinations from the examples on their website, but my every try results in the 403 error with a comment org.json.JSONException: No value for code
and a link to the following:
{
"error": "Daily quota reached or API key unauthorized"
}
(I haven't used that API before, so I couldn't have used up the quota. The key is valid, as I have tested it with the links from the aforementioned website)
My Kotlin code (in my most recent attempt) is as following ([MY_API_KEY] is obviously replacing my real key):
val roadManager = OSRMRoadManager(context, context?.packageName)
(roadManager as OSRMRoadManager).setService("https://api.openrouteservice.org/v2/directions/driving-car/geojson?api_key=[MY_API_KEY]")
val waypoints = ArrayList<GeoPoint>()
waypoints.add(GeoPoint(lastLocLat, lastLocLong)) //last known location
val endPoint = GeoPoint(randomOverlay.getItem(0).point.latitude, randomOverlay.getItem(0).point.longitude) //destination
waypoints.add(endPoint)
val road = roadManager.getRoad(waypoints)
My guess is that the waypoint coordinates should be included differently in the link, but I don't know how to alter that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
openrouteservice 方向格式与 OSRM 不同,因此您不能使用 OSRMRoadManager。
如果你真的-真的-想使用openrouteservice,你就必须开发相应的openrouteserviceRoadManager。
替代方案:使用 OBP 已可访问的 3 个路由服务之一。优点和缺点此处。
openrouteservice directions format is not identical to OSRM, so you cannot use OSRMRoadManager.
If you really - really - want to use openrouteservice, you will have to develop corresponding openrouteserviceRoadManager.
Alternative: use one among the 3 routing services already accessible with OBP. Pros and cons here.