Como encontrar sua localização atual com CoreLocation
Preciso encontrar minha localização atual comCoreLocation
, Tentei vários métodos, mas até agora meuCLLocationManager
retornou apenas 0s. 0.000.00.000
).
Aqui está o meu código updated to work):
Importações:
#import <CoreLocation/CoreLocation.h>
Declarad:
IBOutlet CLLocationManager *locationManager;
IBOutlet UILabel *latLabel;
IBOutlet UILabel *longLabel;
Funçõe:
- (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];
}