如何获取地图上两点之间的路线方向以绘制行车路线?
有没有办法使用核心位置或谷歌或其他一些API来提供地图上的两个点并获取路线的纬度/经度对的结果集?
我在本教程中看到在 MKMapView 上绘制折线或路线如何绘制行驶方向使用核心图形...但在示例代码中它有route.csv,它具有预定义的经度和纬度集...我如何制作一对经度和纬度以便我可以绘制行车方向。
is there a way to use core location or google or some other api to provide two points on the map and get the resulting set of latitude/longitude pairs for the route?
i have seen in this tutorial Drawing polyines or routes on a MKMapView that how to draw driving direction using core graphics...but in the sample code it has route.csv which has predefined set of longitudes and latitudes.....how do i make pair of longitudes and latitudes so that i can draw driving directions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
公司投资数百万美元来开发路由算法,所以我非常怀疑你是否能够在任何地方免费获得它(不过我很高兴我错了)。例如,Google Maps JavaScript API 支持路由,所以我猜你可以破解它。请注意,结果不会很快或漂亮。
Companies invest millions of dollars into developing routing algorithms, so I very much doubt that you'll be able to get it for free anywhere (I'm happy to be wrong, though). For example, the Google Maps JavaScript API supports routing, so I guess you could hack that up. The results wouldn't be fast or pretty, mind you.
如果您对路线请求的使用有限(每天少于一定数量)并且始终在 Google 地图上显示结果,则您确实有资格使用免费的 Google Directions API。
https://developers.google.com/maps/documentation/directions/
阅读彻底许可部分以了解其限制。您应该能够轻松请求 json 响应,该响应比 xml 响应更容易解析(加上 Apple 在 iOS 中添加了 json 解析器)。
例如
http://maps.googleapis.com/maps/api/directions/json?origin=波士顿,马萨诸塞州&目的地=康科德,马萨诸塞州&waypoints=查尔斯敦,马萨诸塞州|列克星敦,马萨诸塞州&sensor=false
如果超出限制,您应该查看他们的营业执照。
If you have a limited use of the directions request (less than a certain amount per day) and always display results on a Google map, you do qualify for the free Google Directions API.
https://developers.google.com/maps/documentation/directions/
Read the license part thoroughly to know the limits. You should easily be able to request a json response that will b easier to parse than an xml one (plus Apple added json parser in iOS).
For example
http://maps.googleapis.com/maps/api/directions/json?origin=Boston,MA&destination=Concord,MA&waypoints=Charlestown,MA|Lexington,MA&sensor=false
If you are over the limit, you should look into their business licenses.
老问题,但 MTDirectionsKit 最近开源并且效果很好:
MTDirectionsKit
Old question but MTDirectionsKit was recently open sourced and it works great:
MTDirectionsKit
使用Google API,您可以从两个点获取路线,唯一的问题是如果您不付费,您每天只能使用一次。
从google上搜索如何获取关键API,youtube上有很多视频在谈论它。
此外,我有一个库可以帮助您在点之间画线这个 https://github.com/jd-alexander/Google-Directions-Android
在
build.gradle(Module:app)
中实现后,实现library
public class LocationMapActivity extends AppCompatActivity Implements RoutingListener
会出现实现方法的错误(必须实现它们,但没有必要<强>使用它们)。
我刚刚这样做了:
链接中的更多信息。
with Google API you can get directions from two points, the only problem is you just can use it once a day if you don't pay.
Search how to get the key API from google, there are a lots of videos on youtube talking about it.
Furthemore, i got a library which hepls you to draw the line between points this one https://github.com/jd-alexander/Google-Directions-Android
After you implemented it in
build.gradle(Module:app)
, implement thelibrary
in the class likepublic class LocationMapActivity extends AppCompatActivity implements RoutingListener
will appear a error to implemets the methods (obligatory to implement them but It's not necessary to use them).
I just did this:
More info in the link.