CLLocationManager在iPhone模拟器上应该假冒库比蒂诺(不是吗?)但它没有,它失败了kCLErrorDomain Code=0.LocationManager的委托接收消息didFailWithError.实现此方法以记录错误,控制台输出以下内容:
Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed. (kCLErrorDomain error 0.)"
Run Code Online (Sandbox Code Playgroud)
当我遇到这个问题时,我正在研究一个真实的项目,但讨论我的代码是没有意义的,因为我从开发中心下载了"Locations"示例代码(iOS 4更新为2010-06-22)并且问题仍然存在.
当应用程序收到第一个位置更新时,该应用程序将启用"添加"按钮,以便用户可以跟踪其位置,但不执行任何操作.
我添加了一个(普通的)行didFailWithError来记录错误,如果有的话.我得到上述错误.
使用Xcode 3.2.2和目标3.1.3,我可以在运行较旧版本的"Locations"项目时获得固定位置(Cupertino).
有人可以帮忙吗?
谢谢.
我的目的是在加载视图时获取用户的经度/纬度,并将值存储在两个变量中以供以后计算.我不需要跟踪用户位置并更新它,我只需要获得他/她的坐标一次.我的代码看起来像这样:
- (void)viewDidLoad {
[super viewDidLoad];
// locationManager update as location
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
[locationManager startUpdatingLocation];
CLLocation *location = [locationManager location];
// Configure the new event with information from the location
CLLocationCoordinate2D coordinate = [location coordinate];
float longitude=coordinate.longitude;
float latitude=coordinate.latitude;
NSLog(@"dLongitude : %f",longitude);
NSLog(@"dLatitude : %f", latitude);
}
Run Code Online (Sandbox Code Playgroud)
在控制台中我一直这样:
dLongitude : 0.000000
dLatitude : 0.000000
Run Code Online (Sandbox Code Playgroud)
你能帮我吗?