简体   繁体   English

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

[英]How to calculate distance and time between two CLLocation throughout the whole ride with CloudMade maps?

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. 在我的iPhone应用程序中,我允许用户在地图上选择一个目的地,然后当他开始开车前往目的地时,我想向他提供类似信息:到达目的地需要多长时间以及距目的地的当前距离。 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. 我正在使用适用于iPhone的CloudMade Maps SDK,我知道有一种API方法可获取两点之间的路径,并返回它们之间的时间和距离。 Is it OK to call this method every time i get a new location from the CLLocationManager to get the updated time and distance? 每次我从CLLocationManager获取新位置以获取更新的时间和距离时,都可以调用此方法吗? 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.. 我假设此方法查询CloudMade服务器,所以我不知道是否多次调用它是执行此操作的最佳方法。

Swift version would be: Swift版本将是:

var startLocation:CLLocation!
var lastLocation: CLLocation!

let distance = startLocation.distanceFromLocation(lastLocation)

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. CLLocation具有速度参数。 Use the distance and the speed to calculate time. 使用距离和速度来计算时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM