- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations {
CLLocation *newlocation = locations[0];
CLLocationCoordinate2D oCoordinate = newlocation.coordinate;
// 给经纬度全局属性赋值
lati = oCoordinate.latitude;
longti = oCoordinate.longitude;
//显示范围,数值越大,范围就越大(后面数字越小 比例约小 可以无限接近0)
MKCoordinateSpan span = {0,0.09};
MKCoordinateRegion region = {oCoordinate,span};
//是否允许缩放,一般都会让缩放的
_mapView.zoomEnabled = YES;
_mapView.scrollEnabled = YES;
//地图初始化时显示的区域
[_mapView setRegion:region];
// 自己位置显示在地图中间
// [_mapView setCenterCoordinate:oCoordinate animated:YES];
[_cllocationManager stopUpdatingLocation];
CLGeocoder *geocoder = [[CLGeocoder alloc]init];
[geocoder reverseGeocodeLocation:newlocation completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
for (CLPlacemark *place in placemarks) {
NSDictionary *location =[place addressDictionary];
NSLog(@"国家:%@",[location objectForKey:@"Country"]);
NSLog(@"城市:%@",[location objectForKey:@"State"]);
NSLog(@"区:%@",[location objectForKey:@"SubLocality"]);
NSLog(@"位置:%@", place.name);
NSLog(@"国家:%@", place.country);
NSLog(@"城市:%@", place.locality);
NSLog(@"区:%@", place.subLocality);
NSLog(@"街道:%@", place.thoroughfare);
NSLog(@"子街道:%@", place.subThoroughfare);
self.title = place.name;
}
}];
}