位置管理器更新频率,iPhone
我有一个名为“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 );
}
有没有办法找到位置管理器更新的频率,以及是否可以增加或减少?
I have a CLLocation manager called "myLocation".
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];
and location update function is
- (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 );
}
Is there a way to find frequency of location manager update, and If it can be increased or decreased?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
仅当您调用方法
[locationManager startUpdatingLocation]
时,您的位置更新才会开始。您可以使用
NSTimer
控制更新频率。当您需要位置更新时,定期调用startUpdatingLocation
方法,然后立即调用stopUpdatingLocation
方法。下次您将仅按照您在NSTimer
中设置的时间间隔获取位置更新。Your location update starts only when you call the method
[locationManager startUpdatingLocation]
.You can control the frequency of the update using an
NSTimer
. Call thestartUpdatingLocation
method at regular intervals whenever you need a location update and then immediately call thestopUpdatingLocation
method. The next time you will get a location update only at the interval you have set in theNSTimer
.为了检测最轻微的移动,您需要设置
但是,请记住,让位置管理器为即使最轻微的移动生成更新也可能导致大量电池使用。
For detecting even the slightest of movements, you need to set
But, please keep in mind,letting location manager to generate updates for even the slightest of movements can end up in lot of battery usage.