// View已经分配了Load Method- LocationManager,并且在.h文件中包含了CLLocationManagerDelegate
-ViewDidLoad{ self.locationManager = [[CLLocationManager alloc] init]; self.locationManager.delegate = self; self.locationManager.desiredAccuracy=kCLLocationAccuracyBest; self.locationManager.distanceFilter=kCLDistanceFilterNone; [self.locationManager requestWhenInUseAuthorization]; [self.locationManager startMonitoringSignificantLocationChanges]; [self.locationManager startUpdatingLocation]; } // Location Manager Delegate Methods - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { NSLog(@"%@", [locations lastObject]); }
答案 0 :(得分:3)
在plist中你必须添加2个条目
将两者的字符串设为"需要位置以找出您的位置"或任何东西
self.locationManager = [[CLLocationManager alloc]init];
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[self.locationManager requestWhenInUseAuthorization];
}
self.locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
CLAuthorizationStatus authorizationStatus= [CLLocationManager authorizationStatus];
if (authorizationStatus == kCLAuthorizationStatusAuthorized ||
authorizationStatus == kCLAuthorizationStatusAuthorizedAlways ||
authorizationStatus == kCLAuthorizationStatusAuthorizedWhenInUse) {
NSLog(@"You are authorized");
}
self.locationManager.delegate = self;
[self.locationManager startUpdatingLocation];
希望这有帮助