您的位置:首页 > 移动开发 > IOS开发

iOS 获取地图视图中心点经纬度

2016-05-30 17:16 363 查看
// 引入系统地图

#import <CoreLocation/CoreLocation.h>

#import <MapKit/MapKit.h>

<CLLocationManagerDelegate,MKMapViewDelegate>// 制定地图代理

- (void)viewDidLoad {

    [super viewDidLoad];

    // 接受代理

    _mapView.delegate = self;

}

// 调用获取中心点坐标代理方法

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {

    MKCoordinateRegion region;

    CLLocationCoordinate2D centerCoordinate = mapView.region.center;

    region.center= centerCoordinate;

    

    NSLog(@" regionDidChangeAnimated %f,%f",centerCoordinate.latitude, centerCoordinate.longitude);

    CLGeocoder *geocoder = [[CLGeocoder alloc]init];

    CLLocation *location = [[CLLocation alloc]initWithLatitude:centerCoordinate.latitude longitude:centerCoordinate.longitude];

    [geocoder reverseGeocodeLocation:location 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);

        }

    }];

    

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: