首页 > 移动平台 > 详细

iOS开发之 使用CLGeocoder实现经纬度和地址互查

时间:2015-08-29 11:15:41      阅读:394      评论:0      收藏:0      [点我收藏+]
  1. 添加CoreLocation.framework框架

  2. 导入#import <CoreLocation/CoreLocation.h>

  3. 通过地址查询经纬度方法:

  4.     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"]);
        }
    }];


iOS开发之 使用CLGeocoder实现经纬度和地址互查

原文:http://my.oschina.net/linxiaoxi1993/blog/498919

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!