您的位置:首页 > 其它

地图与定位之地理编码

2015-04-16 16:49 253 查看
定位学习之后学习地理编码和反编码。

#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


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