计算圈数的最佳技术?

Posted

技术标签:

【中文标题】计算圈数的最佳技术?【英文标题】:Best technique for counting laps? 【发布时间】:2014-01-02 14:22:51 【问题描述】:

我正在制作一个应用程序,该应用程序需要计算参与者在赛道上行走的圈数。我认为我可以在起点周围创建一个小型地理围栏,并让操作系统让我知道用户何时输入它,但这似乎并不像我希望的那样有效。当步行者进入围栏或在轨道周围的其他区域触发时,它似乎没有被可靠地触发。 (此时我正在测试而不让设备进入睡眠状态)。

在我的测试中似乎也没有正确调用 locationManager:didExitRegion 方法。

当用户点击开始按钮时,会调用以下方法:

-(void)startLocationManager 
    if ([CLLocationManager locationServicesEnabled] && usingLocationManager) 
        self.locationManager = [[CLLocationManager alloc] init];
        self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
        self.locationManager.delegate = self;
        self.locationManager.distanceFilter = kCLLocationAccuracyBest;
        self.locationManager.activityType = CLActivityTypeFitness;
        [self.locationManager startUpdatingLocation];
    



- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations       
    CLLocation *lastLocation = [locations lastObject];
    if (lastLocation.horizontalAccuracy > 10) 
        return;
    

    // setup a geocode fence and count as user enters fence
    self.startRegion = [[CLCircularRegion alloc] initWithCenter:lastLocation.coordinate radius:10 identifier:@"startPosition"];
    [self.locationManager stopUpdatingLocation];
    [self.locationManager startMonitoringForRegion:self.startRegion];



-(void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region 
    lapCount++;
    [self updateLapDisplay];

我是不是做错了什么,或者我不能以这种方式使用CoreLocation

【问题讨论】:

【参考方案1】:

地理围栏不能很好地解决这个问题。您不能依靠它来准确或可靠地触发。以正常方式使用位置管理器及其代理,并在用户到达 10 或 20 米内时手动触发,然后在距离它 ​​50 或 100 米时重置触发器。

【讨论】:

以上是关于计算圈数的最佳技术?的主要内容,如果未能解决你的问题,请参考以下文章

使用python计算文件中删除行数的最佳方法

优化 C 代码 [关闭]

excel表格计算列数的公式

睿云智合荣获“2017中国信息技术年度云计算最佳产品奖”

计算给定数的除数的算法

当 runloop 被阻塞时,NSTimer 不会触发