IOS CoreLocation check CLLocation timestamp for its use

How do you check the CLLocation object and decide if you want to use it or discard the result and get a new location update instead?

I saw the timestamp property on CLLocation, but I'm not sure how to compare it with the current time.

Also, after I compare the time and find the difference in seconds, what value should it matter for me to use this CLLocation object? What a good threshold.

Thank!

+3
source share
1 answer

, iOS , Core Location Manager:

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
    CLLocation * newLocation = [locations lastObject];
        //check if coordinates are consistent
        if (newLocation.horizontalAccuracy < 0) {
            return;
        }
        NSTimeInterval interval = [newLocation.timestamp timeIntervalSinceNow];
        //check against absolute value of the interval
        if (abs(interval)<30) {
            //DO STUFF
        }
    }

30 . , .
, ,

+9

Source: https://habr.com/ru/post/1737135/


All Articles