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.
精彩评论