我正在使用
- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLCircularRegion *)region
确定我的用户当前是否在没有跨越边界的区域中。我遇到的问题是给出的状态是
CLRegionStateInside
即使我的位置经理当时的准确度可能是4,000米,如果我甚至不接近边界,更不用说在该区域内,这实际上给了我一个“假状态”。
所以问题是如何消除给定方法中位置管理器给出的这些错误状态?
我考虑过保存准确性以及纬度和经度,并在检查区域状态之前检查它们。但我认为必须有更好的方法。现在我在这里寻找输入。
答案 0 :(得分:0)
我之前尝试了这个并且它似乎没有用,但后来我更改了我的位置管理器的委托,它现在似乎在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
}