в ViewController.m
ужно найти мое текущее местоположение с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];
}