Question

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?

Was it helpful?

Solution 2

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

OTHER TIPS

Your problem is the distance filter setting. kCLLocationAccuracyBest gives you the best data but you'll get updates almost constantly. Now unless you're building a directions/routing application this probably isn't what you want because it's not efficient.

Set the distance filter like so:

_locationManager = [[CLLocationManager alloc] init];
_locationManager.distanceFilter = kCLLocationAccuracyHundredMeters; // One of several options...

Alternatively, as has been mentioned there is a significant change API that you can use to receive updates. These will occur less frequently by design, but you don't have much control over how often you receive the updates.

Call this method to start receiving those updates:

[_locationManager startMonitoringSignificantLocationChanges]

Its most common to do this while your app is backgrounded.

Check the docs for more info:

https://developer.apple.com/library/mac/documentation/CoreLocation/Reference/CLLocationManager_Class/CLLocationManager/CLLocationManager.html

just use startMonitoringSignificantLocationChanges is should help also set distanceFilter

And of course refer to docs CLLocationManager Class Reference

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top