我有一个名为“myLocation”的CLLocation管理器。
myLocation = [[CLLocationManager alloc] init];
myLocation.desiredAccuracy = kCLLocationAccuracyBestForNavigation ;
myLocation.distanceFilter = 10 ;
myLocation.delegate=self;
locationEnabledBool = [CLLocationManager locationServicesEnabled];
if (locationEnabledBool ==NO || ( [CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied)) {
// LocationText.text = @"Location Service Disabled ";
UIAlertView *locationAlert = [[UIAlertView alloc] initWithTitle:@"Location Service Disabled"
message:@"To re-enable, please go to Settings and turn on Location Service for this app."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[locationAlert show];
[locationAlert release];
}
[myLocation startUpdatingLocation];
和位置更新功能
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
NSLog(@"old location is %f, %f ", oldLocation.coordinate.latitude, oldLocation.coordinate.longitude);
NSLog(@"new location is %f,%f",newLocation.coordinate.latitude, newLocation.coordinate.longitude );
}
有没有办法找到位置管理器更新的频率,如果可以增加或减少?
答案 0 :(得分:21)
只有在调用方法[locationManager startUpdatingLocation]
时才会启动位置更新。
您可以使用NSTimer
控制更新的频率。每当需要更新位置时,定期调用startUpdatingLocation
方法,然后立即调用stopUpdatingLocation
方法。下次您只能按照NSTimer
中设置的时间间隔更新位置信息。
答案 1 :(得分:2)
为了检测最轻微的动作,您需要设置
myLocation.distanceFilter = kCLDistanceFilterNone ;
但是,请记住,让位置管理员生成更新,即使是最轻微的动作也会导致大量电池使用。