我正在构建一个应用程序,它需要我找到指定位置和我当前位置之间的距离。我使用CLLocationManager
的是相同的,但检索到的坐标是 0,0,尽管我在模拟器中指定了自定义位置。这是代码:.m 文件
@property (nonatomic, strong) CLLocationManager *locationManager2;
...
@synthesize locationManager2;
- (CLLocationManager *)locationManager2 {
if (locationManager2 != nil) {
return locationManager2;
}
locationManager2 = [[CLLocationManager alloc] init];
[locationManager2 setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];
[locationManager2 setDelegate:self];
return locationManager2;
}
...
...
...
CLLocation *locationHome = [locationManager2 location];
NSLog(@"%f",locationHome.coordinate.latitude);
纬度记录为零。我的代码有什么问题吗?