有没有办法控制位置管理器的更新间隔?为了准确起见,我使用了最近的10米设置,但我的应用程序似乎每秒都会更新一次,我认为这太频繁了。我想要好的准确度,但不是频率。
谢谢。
发布于 2011-08-01 02:40:10
我是用计时器做的:
在标题中添加:
ServerInterface *serverInterface;在.m文件中:
- (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
} 在你的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];
}代码只是在达到100m的最小精度后停止更新位置。然后,每隔30秒就会有一个定时器再次启用locationmanager。
https://stackoverflow.com/questions/6803410
复制相似问题