ios7 programming cookbook 第九章学习笔记

####Converting Longitude and Latitude to a Meaningful Address

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
@interface  ()

@property (nonatomic, strong) CLGeocoder *myGeocoder;
@end

- (void)viewDidLoad{
[super viewDidLoad];
//Latitude 纬度
//longitude 经度
CLLocation *location = [[CLLocation alloc]initWithLatitude:-38.4112810 longitude:-122.8409780f];

self.myGeocoder = [[CLGeocoder alloc] init];

//提交一个reverse-geocoding请求指定的位置。
[self.myGeocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {

if (error == nil && placemarks.count > 0){
CLPlacemark *placemark = placemarks[0];
/*results */
NSLog(@"Country = %@", placemark.country);
NSLog(@"Postal Code = %@", placemark.postalCode);
NSLog(@"Locality = %@", placemark.locality);
}
else if (error == nil && placemarks.count == 0){
NSLog(@"没有结果返回.");
}
else if (error != nil){
//发生一个错误 = Error Domain=kCLErrorDomain Code=8 "The operation couldn’t be completed. (kCLErrorDomain error 8.)"
NSLog(@"发生一个错误 = %@", error);
}

}];
}

Reference