定位学习之后学习地理编码和反编码。
#import "ViewController.h"
#import <CoreLocation/CoreLocation.h>
@interface ViewController ()<CLLocationManagerDelegate>
@property(nonatomic,strong)CLGeocoder *cLGeocoder;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSString *address=@"天安门";
CLLocation *clLocation=[[CLLocation alloc]initWithLatitude:39.54 longitude:116.28];
_cLGeocoder=[[CLGeocoder alloc]init];
//编码
[_cLGeocoder geocodeAddressString:address completionHandler:^(NSArray *placemarks, NSError *error) {
CLPlacemark *placemark=[placemarks firstObject];
CLLocation *cllocation=placemark.location;
CLRegion *clRegion=placemark.region;
NSDictionary *addressdic=placemark.addressDictionary;
NSLog(@"编码: %@ %@ %@",cllocation,clRegion,addressdic);
}];
//反编码
[_cLGeocoder reverseGeocodeLocation:clLocation completionHandler:^(NSArray *placemarks, NSError *error) {
CLPlacemark *placemark=[placemarks firstObject];
NSLog(@"反编码: %@",placemark);
}];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end