申明:此为本人学习笔记,若有纰漏错误之处的可留言共同探讨
/*
正向编码(有具体地址 --求出--》经纬度) 步骤:初始化CLGeocoder 、使用geocodeAddressString方法
反向编码(有经纬度 --求出--》具体地址) 步骤:初始化CLGeocoder 、使用reverseGeocodeLocation方法
*/
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 初始化
myGeocoder = [[CLGeocoder alloc]init];
// // 正向编码
// [myGeocoder geocodeAddressString:@"雁盟文化产业园" completionHandler:^(NSArray *placemarks, NSError *error) {
// [self showMarkInfo:placemarks];
// }];
// 反向编码22.581650,113.891518
CLLocation *location = [[CLLocation alloc]initWithLatitude:22.581650 longitude:113.891518];
[myGeocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {
[self showMarkInfo:placemarks];
}];
}
#pragma mark - 地点信息
-(void)showMarkInfo:(NSArray*)placemarks
{
// 数组中的每个元素都是CLOlaceMark类型对象
for (CLPlacemark *mark in placemarks) {
CLLocation *location = mark.location;
// 经纬度
NSLog(@"%f,%f",location.coordinate.latitude,location.coordinate.longitude);
NSLog(@"全名 %@",mark.name); // 全名
NSLog(@"城市 %@",mark.location); // 城市
NSLog(@"街道 %@",mark.thoroughfare); // 街道
NSLog(@"区县 %@",mark.subLocality); // 区县
}
}
附上完整demo:http://download.csdn.net/detail/csdn_hhg/9218109