原因是CLLocationManager用的是临时变量ARC下会自动释放,所以才没有弹出提示框和代理方法
/*************************************************/
//定位的使用方法
@property (strong, nonatomic) CLLocationManager *LocationManager;
- (void)viewDidLoad {
[super viewDidLoad];
_LocationManager = [[CLLocationManager alloc]init];//初始化
_LocationManager.delegate = self;//设置代理
_LocationManager.desiredAccuracy = kCLLocationAccuracyBest;//定位精确度
_LocationManager.distanceFilter = 10.0f;//定位半径
[_LocationManager requestWhenInUseAuthorization];//使用时使用定位
[_LocationManager startUpdatingLocation];//开始定位
}
#pragma mark - 定位代理经纬度回调
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
[manager stopUpdatingLocation];
NSLog(@"%@",[NSString stringWithFormat:@"经度:%3.5f\n纬度:%3.5f",newLocation.coordinate.latitude,newLocation.coordinate.longitude]);
CLGeocoder * geoCoder = [[CLGeocoder alloc] init];
[geoCoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
for (CLPlacemark * placemark in placemarks) {
NSDictionary *test = [placemark addressDictionary];
// Country(国家) State(省份) City(城市) SubLocality(区)
NSString *cityString = [test objectForKey:@"City"];
}
}];
}