如何使用 CloudMade 地图计算整个骑行过程中两个 CLLocation 之间的距离和时间?

发布于 2024-12-06 14:57:41 字数 256 浏览 5 评论 0原文

在我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

汐鸠 2024-12-13 14:57:41

对于距离的

/*
 *  distanceFromLocation:
 *
 *  Discussion:
 *    Returns the lateral distance between two locations.
 */
- (CLLocationDistance)distanceFromLocation:(const CLLocation *)location __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_3_2);

获取所需要的时间,你可以自己计算一下。 CLLocation 有一个速度参数。使用距离和速度来计算时间。

For distance

/*
 *  distanceFromLocation:
 *
 *  Discussion:
 *    Returns the lateral distance between two locations.
 */
- (CLLocationDistance)distanceFromLocation:(const CLLocation *)location __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_3_2);

For getting the time needed, you could calculate it yourself. CLLocation has a speed parameter. Use the distance and the speed to calculate time.

神爱温柔 2024-12-13 14:57:41

Swift 版本是:

var startLocation:CLLocation!
var lastLocation: CLLocation!

let distance = startLocation.distanceFromLocation(lastLocation)

Swift version would be:

var startLocation:CLLocation!
var lastLocation: CLLocation!

let distance = startLocation.distanceFromLocation(lastLocation)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文