Ios位置更新继续到达didUpdateLocations

时间:2015-03-24 09:31:49

标签: ios objective-c cllocationmanager

我需要在应用启动后检查位置并将其发送到服务器。之后,我需要检查每公里的位置。

因此,当我开始更新位置时,我将distanceFilter设置为none,在第一个位置接收时,我将其更改为1公里。

  //If the location update is denied
    if ([CLLocationManager authorizationStatus]==kCLAuthorizationStatusDenied)
        [ self locationUpdateDenied:basicViewController];
    else if ([CLLocationManager locationServicesEnabled]) {
        _locationManager.desiredAccuracy = kCLLocationAccuracyBest;
        _locationManager.distanceFilter=kCLDistanceFilterNone;

        //In ViewDidLoad
        if([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
            [self.locationManager requestWhenInUseAuthorization];
        }
        [_locationManager startUpdatingLocation];
    }

收到第一个位置:

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{

    if (locations>0) {
        [_locationManager setDistanceFilter:1000.0f];

        CLLocation *location = [locations objectAtIndex:0];
        [User sharedInstance].latitude=location.coordinate.latitude;
        [User sharedInstance].longitude=location.coordinate.longitude;
      /*  if (!_delegate) {
            [_delegate userLocationUpdated];
        }*/
    }
}

它一直在检查位置的问题。位置没有变化,但它仍然到达didUpdateLocations。它就像distanceFilter没有改变。

我是否需要停止位置更新并将其与公里距离过滤?

1 个答案:

答案 0 :(得分:1)

从文档中我假设您可以在启动位置服务之前设置distanceFilter属性,因为在您使用startUpdatingLocation第一个位置启动服务后,您将被称为immediatley。

[manager setDistanceFilter:1000.0];
[manager startUpdatingLocation]; // will call didUpdateLocations immediatley
                                 // with the current location