开发者

Control location manager update interval

开发者 https://www.devze.com 2023-03-22 23:22 出处:网络
Is there a way to control the update interval of the location m开发者_如何学Canager? I used the nearest 10 meter setting for accuracy but it appears that my application gets one update every second, w

Is there a way to control the update interval of the location m开发者_如何学Canager? I used the nearest 10 meter setting for accuracy but it appears that my application gets one update every second, which I think is too often. I want the good accuracy but not the frequency.

Thanks.


I did it with a timer:

in the header add:

ServerInterface *serverInterface;

in the .m file:

- (void)viewDidLoad
{
...
[frequentLocationUpdateTimer invalidate];
frequentLocationUpdateTimer = [NSTimer scheduledTimerWithTimeInterval:30 target:self selector:
               @selector(reEnableLocationTick:) userInfo:nil repeats:YES];
...
}
- (void)reEnableLocationTick:(NSTimer *)theTimer
{
    [locationGetter startUpdates]; //Maybe you have to change this line according to your code
} 

and in your locationmanager...:

- (void)locationManager:(CLLocationManager *)manage didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    ...

        if (newLocation.horizontalAccuracy < 100)
    {
        [locationManager stopUpdatingLocation];  
    } 
    ...

    // let our delegate know we're done
    [delegate newPhysicalLocation:newLocation];
}

The code simply stops updating the location after reaching a minimum accuracy of 100m. Then, every 30sec a timer reenables the locationmanager again.

0

精彩评论

暂无评论...
验证码 换一张
取 消