【发布时间】:2014-10-04 08:23:48
【问题描述】:
我需要在我的程序中计算所有 gps 参数,所以我使用这段代码:
(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
CLLocation* loc = [locations lastObject];
它收集 loc 对象中的所有 gps 测量值(高度、速度等),我有纬度/经度信息(loc.coordinate.lattitude 和 loc.coordinate.longitude)但这些是新的测量坐标。
由于我还想计算测量之间的距离,如何从 didUpdateLocations 方法中检索“新”坐标和“旧”坐标?
如果我在程序中使用 didUpdateToLocation 方法添加另一个 locationManager 调用(这将给出新旧坐标):
(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
根本没有调用初始locationManager方法(didUpdateLocations),所以无法计算所有gps数据加上距离...
【问题讨论】:
-
您列出的第二种方法已被弃用 - 由第一种方法取代,但如果您实施它,则第一种方法不会被调用 - 正如您所发现的那样。您需要将先前的位置存储在属性中,并在下次调用时根据此位置进行比较/计算
-
作为 iOS 编程新手,如何将位置对象复制到另一个对象(即旧位置),在 CLLocationManage 之外可见(这样我就可以比较下一个 CLLocationManager 上的最新位置数据方法调用)?我可以访问 loc 对象的 lat/long 属性,但我将调用的 CLLocationDistance 方法需要对象作为参数,而不是属性。
-
只需为您的类创建一个存储 CLLocation 的属性
标签: ios gps cllocationmanager cllocation