简体   繁体   English

iOS位置更新不断到达didUpdateLocations

[英]Ios location update keep getting to the didUpdateLocations

I need once the app is launch, to check the location and send it to the server. 应用启动后,我需要检查位置并将其发送到服务器。 After it, i need to check the location every kilometer. 之后,我需要检查每公里的位置。

So when i started the location update, i set the distanceFilter to none and on the first location receive, i changed it to 1 kilometer. 因此,当我开始位置更新时,我将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];
    }

The first location receive: 第一个位置收到:

- (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];
        }*/
    }
}

the problem it keeps checking the location. 问题,它不断检查位置。 The location isn't changing but it still gets to the didUpdateLocations. 位置没有改变,但仍然可以到达didUpdateLocations。 It like the distanceFilter isn't changing. 就像distanceFilter没变一样。

should i need to stop the location update and reactive it with the kilometer distanceFilter? 我是否需要停止位置更新并使用公里distanceFilter进行反应?

From the documentation i presume that you can set the distanceFilter property before you start the location service since you will be called immediatley after you start the service with startUpdatingLocation with a first location. 从文档中,我认为您可以在启动定位服务之前设置distanceFilter属性,因为在启动具有第一个位置的startUpdatingLocation服务后,您将被立即称为。

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

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

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