标签:
添加CoreLocation.framework框架
导入#import <CoreLocation/CoreLocation.h>
通过地址查询经纬度方法:
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:@"湖北襄阳" completionHandler:^(NSArray* placemarks, NSError* error){
if (!error) {
for (CLPlacemark* aPlacemark in placemarks)
{
NSLog(@"place--%@", [aPlacemark locality]);
NSLog(@"lat--%f--lon--%f",aPlacemark.location.coordinate.latitude,aPlacemark.location.coordinate.longitude);
}
}
else{
NSLog(@"error--%@",[error localizedDescription]);
}
}];5. 通过经纬度查询地址方法:
CLLocation * newLocation = [[CLLocation alloc]initWithLatitude:30.590865 longitude:104.061792];
NSLog(@"-------根据经纬度反查地理位置--%f--%f",senderCoordinate.latitude,senderCoordinate.longitude);
CLGeocoder *clGeoCoder = [[CLGeocoder alloc] init];
[clGeoCoder reverseGeocodeLocation:newLocation completionHandler: ^(NSArray *placemarks,NSError *error) {
NSLog(@"--array--%d---error--%@",(int)placemarks.count,error);
if (placemarks.count > 0) {
CLPlacemark *placemark = [placemarks objectAtIndex:0];
NSString *city = placemark.administrativeArea;
NSLog(@"位于:%@",city);
NSLog(@"%@",placemark.addressDictionary[@"Name"]);
}
}];
标签:
原文地址:http://my.oschina.net/linxiaoxi1993/blog/498919