IOS地址解析成经纬度-精简版

来源:互联网 发布:知乎 梵高 被高估 编辑:程序博客网 时间:2024/05/16 01:35

IOS地址解析成经纬度-精简版

#import <CoreLocation/CoreLocation.h>


CLGeocoder *_geocoder;


_geocoder=[[CLGeocoder alloc]init];


#pragma mark 根据地名确定地理坐标,address为详细地址

-(void )getCoordinateByAddress:(NSString *)address{

    //地理编码

    [_geocoder geocodeAddressString:address completionHandler:^(NSArray *placemarks, NSError *error) {

        //取得第一个地标,地标中存储了详细的地址信息,注意:一个地名可能搜索出多个地址

        CLPlacemark *placemark=[placemarks firstObject];

        

        CLLocation *location=placemark.location;//位置

        CLRegion *region=placemark.region;//区域

        NSDictionary *addressDic= placemark.addressDictionary;//详细地址信息字典,包含以下部分信息

    

        NSLog(@"位置:%@,区域:%@,详细信息:%@",location,region,addressDic);

        

        CLLocationDegrees latitude=location.coordinate.latitude;

        CLLocationDegrees longitude=location.coordinate.longitude;

         

           //传给接口的纬度和经度

           _latitude=[NSString stringWithFormat:@"%lf",latitude];

           _longitude=[NSString stringWithFormat:@"%lf",longitude];

       

        NSLog(@"地址纬度-->%@,经度-->%@",_latitude,_longitude);

        

        //调用添加收货地址的接口

        [self AddRecieveInfo];

   

        

    }];

    

}


0 0
原创粉丝点击