Мне нужно найти текущее местоположение с помощью CoreLocation
, я попробовал несколько методов, но до сих пор мой CLLocationManager
возвращал только 0.. (0.000.00.000
).
Здесь мой код (обновлен для работы):
Импорт
#import <CoreLocation/CoreLocation.h>
Заявлен:
IBOutlet CLLocationManager *locationManager;
IBOutlet UILabel *latLabel;
IBOutlet UILabel *longLabel;
Функции:
- (void)getLocation { //Called when needed
latLabel.text = [NSString stringWithFormat:@"%f", locationManager.location.coordinate.latitude];
longLabel.text = [NSString stringWithFormat:@"%f", locationManager.location.coordinate.longitude];
}
- (void)viewDidLoad {
locationManager = [[CLLocationManager alloc] init];
locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
[locationManager startUpdatingLocation];
}