IPhone simulator is always zero

I am trying to develop Altimeter on Xcode and Simulator, but it always returns 0 for altitude. I do not understand why, I tried with a lot of places on the Simulator.

My code is:

- (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];
}

Where is my mistake?

+4
source share
1 answer

There is nothing wrong with the code because you are using a simulator.

GPS, GPS , ( Wi-Fi- GPS). iOS , . GPS .

CLLocation , CLLocation :

- (id)initWithCoordinate:(CLLocationCoordinate2D)coordinate
    altitude:(CLLocationDistance)altitude
    horizontalAccuracy:(CLLocationAccuracy)hAccuracy
    verticalAccuracy:(CLLocationAccuracy)vAccuracy
    timestamp:(NSDate *)timestamp

Altitude - readonly, CLLocation , , , CLLocation .

+3

Source: https://habr.com/ru/post/1525810/


All Articles