【发布时间】:2012-03-28 14:13:01
【问题描述】:
我在我的应用程序的不同视图中使用 CLLocationManager,当从后台状态返回时,某种冻结大约 2 到 3 秒,没有响应用户交互。
在我的 AppDelegate 中,我正在使用以下代码:
_locationManager = [[CLLocationManager alloc] init];
// Get the location if the user
if ([CLLocationManager locationServicesEnabled])
{
[self.locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];
[self.locationManager setDistanceFilter:50];
[self.locationManager startUpdatingLocation];
}
在其他视图中我正在使用此代码:
_locationManager = [[CLLocationManager alloc] init];
if ([CLLocationManager locationServicesEnabled])
{
[self.locationManager setDelegate:self];
[self.locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];
[self.locationManager setDistanceFilter:50];
[self.locationManager startUpdatingLocation];
}
// Delegate
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
// Set the map view to the current location
MKCoordinateSpan span;
span.latitudeDelta = 0.01;
span.longitudeDelta = 0.02;
MKCoordinateRegion region;
region.span = span;
region.center = newLocation.coordinate;
[_mapView setRegion:region animated:YES];
}
【问题讨论】:
-
您在后台时需要位置吗?那你能不能停止更新位置?
-
这个问题缺乏细节。我使用 CLLocationManager 并没有发现问题。您是否隔离了导致延迟的代码行?如果不打开 locationmanger 会怎样?
-
如果我不打开位置管理器,我没有任何问题
标签: iphone cocoa-touch ipad core-location cllocationmanager