【发布时间】:2023-11-06 12:11:01
【问题描述】:
我正在尝试在 Xcode 和 Simulator 上开发一个高度计,但对于海平面以上的高度,它总是返回 0。 我不明白为什么,我在模拟器上尝试了很多地方。
我的代码是这样的:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
_mapView.delegate = self;
_locationManager = [[CLLocationManager alloc] init];
_locationManager.desiredAccuracy = kCLLocationAccuracyBest;
_locationManager.pausesLocationUpdatesAutomatically = YES;
_locationManager.delegate = self;
firstLocation = YES;
checkUserLocation = NO;
}
- (void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
CLLocation *location = [locations lastObject];
lastLocation = location.coordinate;
_latitudeLabel.text = [NSString stringWithFormat:@"Current latitude: %f", location.coordinate.latitude];
_longitudeLabel.text = [NSString stringWithFormat:@"Current longitude: %f", location.coordinate.longitude];
_altitudeLabel.text = [NSString stringWithFormat:@"Current altitude: %f m", location.altitude];
}
我的错误在哪里?
【问题讨论】:
标签: ios cocoa-touch gps ios-simulator cllocationmanager