【问题标题】:How can I eliminate false states of my monitored region in the location manager's didDetermineState method?如何在位置管理器的 didDetermineState 方法中消除我监控区域的错误状态?
【发布时间】:2015-03-20 14:15:58
【问题描述】:

我正在使用

- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLCircularRegion *)region

确定我的用户当前是否在没有跨越边界的区域中。我遇到的问题是给定的状态是

CLRegionStateInside

即使我的位置管理器当时的准确度可能是 4,000 米,如果我什至不靠近边界,更不用说在该区域内,这基本上给了我一个“错误状态”。

那么问题是如何消除位置管理器在给定方法中给出的这些错误状态?

我考虑在检查该地区的状态之前将精度与经纬度一起保存并检查它们。但我认为必须有更好的方法。现在我在这里寻找输入。

【问题讨论】:

    标签: ios cllocationmanager geofencing


    【解决方案1】:

    我之前尝试过,但它似乎不起作用,但后来我更改了我的位置管理器的委托,现在它似乎在 didDeterminState 方法中工作。

    CLLocation* location = [self.locationManager location];
    NSDate* eventDate = location.timestamp;
    float accuracy = location.horizontalAccuracy;
    NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];
    CLLocation* regionLocation = [[CLLocation alloc] initWithLatitude:region.center.latitude longitude:region.center.longitude];
    CLLocationDistance distance = [location distanceFromLocation:regionLocation];    
    
    if (state == CLRegionStateInside && abs(howRecent) < 10 && accuracy <= 100 && distance < region.radius)
    {
        //Do Something
    }
    

    【讨论】:

      猜你喜欢
      • 2017-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-04
      • 1970-01-01
      • 2016-11-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多