繁体   English   中英

如何从CLLocationManager同时计算所有gps数据

[英]How to calculate ALL gps data from CLLocationManager at the same time

我需要在程序中计算所有gps参数,因此我使用以下代码:

(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
    CLLocation* loc = [locations lastObject]; 

它收集了loc对象中的所有gps测量值(高度,速度等),我有经/纬度信息( loc.coordinate.lattitudeloc.coordinate.longitude ),但这是新的测量坐标。

由于我还想计算测量之间的距离,如何从didUpdateLocations方法中检索“新”坐标和“旧”坐标?

如果我在程序中使用didUpdateToLocation方法添加了另一个locationManager调用(它将提供新旧坐标):

(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation
    fromLocation:(CLLocation *)oldLocation {

根本没有调用初始locationManager方法(didUpdateLocations),所以我无法计算所有gps数据加上距离...

成功复制属性后,我有了下面的工作代码,但我无法理解:

  • (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {_locManagerIteration ++; NSLog(@“位置管理器迭代=%ld”,_ locManagerIteration);

    CLLocation * loc = [locations lastObject]; //确保位置至少有一个对象

    if(_locManagerIteration == 1){//初始化第一个过去的协调对象self.pastCoordinate = [locations lastObject]; } else {CLLocationDistance _pointDistance = [self.pastCoordinate distanceFromLocation:loc]; NSLog(@“点对点距离=%f”,_pointDistance); self.pastCoordinate = [locations lastObject]; } NSLog(@“点对点距离=%f”,_pointDistance);

    _totalDistance = _totalDistance + _pointDistance; // COMPUTE T​​OTAL DISTANCE _totalDistance = _totalDistance / 1000; //在公里中翻译总距离在上一节中,CLLocationDistance调用正确地将距离(以米为单位)放置在我的全局变量_pointDistance中。 我打印_pointDistance变量,然后看到数字(NSLog ...)。 但是,当我再次在if-then语句外打印相同的全局变量时,该值始终为零...

在else括号内,_pointDistance变量在XCODE中为黑色(并打印该值),在else括号外以绿色显示,并且该值归零。...毫无意义。

暂无
暂无

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

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