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);
}
}];
}
#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);
}
}];
}
相关文章推荐
- [置顶] iOS自定义日期并进行卡控
- IOS 开发中的KVC 和KVO
- std::ios::sync_with_stdio(false);
- iOS Quartz2D的基本图形绘制
- iOS原生CIFilter创建二维码
- ios开发——支付宝SDK集成流程
- iOS 离屏渲染研究
- iOS CGContextRef的使用
- ios开发——CMDeviceMotion陀螺仪的使用
- iOS视图对象的生命周期
- iOS 短信验证码倒计时按钮的实现
- 正则表达式
- iOS9创建PCH文件
- iOS 开发疑难杂症
- CIFilter应用:多图叠加合成
- iOS 宏(define)与常量(const)的正确使用
- iOS 浅拷贝(Shallow Copy)与深拷贝(Deep Copy)
- 【iOS开发】获取当前view(视图)所在的Controller(控制器)
- iOS应用程序生命周期(前后台切换,应用的各种状态)详解
- iOS 两日期之间相差几天