7.8 Converting Longitude and Latitude to a Meaningful Address

来源:互联网 发布:西安软件行业 编辑:程序博客网 时间:2024/04/30 08:32



通过经纬度获取地址信息

- (void)viewDidLoad

{

    [superviewDidLoad];

CLLocation *location = [[CLLocationalloc]initWithLatitude:39.904989

                                                     longitude:116.405285];

   self.myGeocoder = [[CLGeocoderalloc]init];

    [self.myGeocoder

    reverseGeocodeLocation:locationcompletionHandler:^(NSArray *placemarks,NSError *error) {

        if (error ==nil && [placemarkscount] >0){

            CLPlacemark *placemark = [placemarksobjectAtIndex:0];/* We received the results */

            NSLog(@"Country = %@", placemark.country);

            NSLog(@"name = %@", placemark.name);

            NSLog(@"thoroughfare = %@", placemark.thoroughfare);

            NSLog(@"subThoroughfare = %@", placemark.subThoroughfare);

            NSLog(@"locality = %@", placemark.locality);

            NSLog(@"subLocality = %@", placemark.subLocality);

            NSLog(@"administrativeArea = %@", placemark.administrativeArea);

             NSLog(@"subAdministrativeArea = %@", placemark.subAdministrativeArea);

            NSLog(@"postalCode = %@", placemark.postalCode);

            NSLog(@"ISOcountryCode = %@", placemark.ISOcountryCode);

            NSLog(@"inlandWater = %@", placemark.inlandWater);

            NSLog(@"ocean = %@", placemark.ocean);

            NSLog(@"areasOfInterest = %@", placemark.areasOfInterest);

         }

        elseif (error ==nil &&

                  [placemarkscount] ==0){

             NSLog(@"No results were returned.");

         }

        elseif (error !=nil){

            NSLog(@"An error occurred = %@", error); }

     }];

}



输出:

2014-04-08 14:12:59.756 cookbook[592:c07] Country = China

2014-04-08 14:12:59.758 cookbook[592:c07] name = Danta Coffee

2014-04-08 14:12:59.758 cookbook[592:c07] thoroughfare = Danta Coffee

2014-04-08 14:12:59.758 cookbook[592:c07] subThoroughfare = (null)

2014-04-08 14:12:59.759 cookbook[592:c07] locality = (null)

2014-04-08 14:12:59.759 cookbook[592:c07] subLocality = Dongcheng

2014-04-08 14:12:59.760 cookbook[592:c07] administrativeArea = Beijing

2014-04-08 14:12:59.760 cookbook[592:c07] subAdministrativeArea = (null)

2014-04-08 14:12:59.760 cookbook[592:c07] postalCode = (null)

2014-04-08 14:12:59.760 cookbook[592:c07] ISOcountryCode = CN

2014-04-08 14:12:59.761 cookbook[592:c07] inlandWater = (null)

2014-04-08 14:12:59.761 cookbook[592:c07] ocean = (null)

2014-04-08 14:12:59.761 cookbook[592:c07] areasOfInterest = (null)





如果输入的经纬度是:

CLLocation *location = [[CLLocationalloc] initWithLatitude:24.5

                                                     longitude:118.13];


则输出是:

2014-04-08 14:16:19.442 cookbook[613:c07] Country = China

2014-04-08 14:16:19.443 cookbook[613:c07] name = No. 1389 Xianyue Road

2014-04-08 14:16:19.443 cookbook[613:c07] thoroughfare = Xianyue Road

2014-04-08 14:16:19.444 cookbook[613:c07] subThoroughfare = No. 1389

2014-04-08 14:16:19.444 cookbook[613:c07] locality = Xiamen

2014-04-08 14:16:19.444 cookbook[613:c07] subLocality = Huli

2014-04-08 14:16:19.444 cookbook[613:c07] administrativeArea = Fujian

2014-04-08 14:16:19.445 cookbook[613:c07] subAdministrativeArea = (null)

2014-04-08 14:16:19.445 cookbook[613:c07] postalCode = (null)

2014-04-08 14:16:19.445 cookbook[613:c07] ISOcountryCode = CN

2014-04-08 14:16:19.445 cookbook[613:c07] inlandWater = (null)

2014-04-08 14:16:19.446 cookbook[613:c07] ocean = (null)

2014-04-08 14:16:19.446 cookbook[613:c07] areasOfInterest = (null)



0 0
原创粉丝点击