3
我使用CLLocationManager来确定我的当前位置:CLLocationManager没有在的iOS 4.3模拟器工作
- (void)viewDidLoad
{
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
[locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
self.currentLocation = newLocation;
NSTimeInterval locationAge = -[newLocation.timestamp timeIntervalSinceNow];
if (locationAge > 5.0) return;
if (newLocation.horizontalAccuracy < 0) return;
if (self.currentLocation == nil || self.currentLocation.horizontalAccuracy > newLocation.horizontalAccuracy) {
self.currentLocation = newLocation;
}
[locationManager stopUpdatingLocation];
}
它工作在5.1的iOS模拟器,但不是的iOS 4.3模拟器,我想这可能是一个在iOS 5.1之前的真实设备中出现问题。为什么它不起作用?
你能描述一下你的意思吗?不工作。委托方法根本没有被调用?也许尝试设置desiredAccuracy过滤器。检查授权状态。实现didFail方法,看看它是否下降到那里 – Mike 2012-08-16 13:24:57
确保在尝试使用CCLocationManager之前检查'[CLLocationManager locationServicesEnabled]',即使在模拟器中,您的位置服务也可以关闭。 – Joe 2012-08-16 13:26:06
我试过“locationServicesEnabled”方法,你是对的乔,位置服务没有启用。那么,我该如何启用它,或者我该怎么做? – realuser 2012-08-16 13:36:11