如何使用 CloudMade 地图计算整个骑行过程中两个 CLLocation 之间的距离和时间?
在我的 iPhone 应用程序中,我允许用户在地图上选择目的地,然后当他开始驶向目的地时,我想向他提供以下信息:他到达目的地需要多长时间以及距目的地的当前距离。我正在使用适用于 iPhone 的 CloudMade 地图 SDK,我知道有一个 API 方法可以获取两点之间的路径,同时返回两点之间的时间和距离。每次我从 CLLocationManager 获取新位置以获取更新的时间和距离时都可以调用此方法吗?我假设这个方法查询 CloudMade 服务器,所以我不知道大量调用它是否是最好的方法。
In my iPhone application I allow the user to choose a destination on the map, then when he starts driving toward the destination I want to give him information like: how long until he reaches the destination and what its current distance from the destination. I'm using CloudMade maps SDK for iPhone and i know there is an API method to get a path between two point that returns also the time and distance between them. Is it OK to call this method every time i get a new location from the CLLocationManager to get the updated time and distance? I assume this method query the CloudMade servers so i don't know if calling it a lot of time is the best way to do this..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于距离的
获取所需要的时间,你可以自己计算一下。 CLLocation 有一个速度参数。使用距离和速度来计算时间。
For distance
For getting the time needed, you could calculate it yourself. CLLocation has a speed parameter. Use the distance and the speed to calculate time.
Swift 版本是:
Swift version would be: