Search code examples
ioscllocationmanagercllocation

Update location from time to time


I´m getting updates of my location using the below code:

- (id)init {
    if (self = [super init]) 
    {
        locationManager = [[CLLocationManager alloc] init];
        locationManager.delegate = self;
        locationManager.distanceFilter = kCLDistanceFilterNone;
        locationManager.desiredAccuracy = kCLLocationAccuracyBest;
        [locationManager startUpdatingLocation];
    }

    return self;
}

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    NSLog(@"Location: %@", [locations lastObject]);
}

Everything works fine, the problem is that the updates are coming with 1 second of interval. Is there any way to make the intervals longer?


Solution

  • Option 1

    Use - (void)startMonitoringSignificantLocationChanges on your location manager which will update events only when a significant change in the user’s location is detected. For example, it might generate a new event when the device becomes associated with a different cell tower.

    Option 2

    You can try to reduce the accuracy of monitoring.

    locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
    [locationManager startUpdatingLocation];
    

    Do not use kCLDistanceFilterNone as it will report every movement.

    "All movements are reported"

    and set accuracy value to something among:

    kCLLocationAccuracyNearestTenMeters
    kCLLocationAccuracyHundredMeters 
    kCLLocationAccuracyKilometer 
    kCLLocationAccuracyThreeKilometers