CLGeocoder地址获取经纬度,经纬度获取地址iOS

Posted on 2013-12-06 16:41  逍_遥  阅读(515)  评论(0)    收藏  举报

        // 苹果自带编码

        

       CLGeocoder *geocoder = [[CLGeocoder alloc] init];

        // 通过地址获取经纬度

        [geocoder geocodeAddressString:@"呼和浩特" completionHandler:^(NSArray *placemarks, NSError *error) {

           if (placemarks.count>0) {

               CLPlacemark *placemark = [placemarks objectAtIndex:0];

               NSLog(@"%@",placemark.location);

            }

        }];

        // 通过经纬度获取地址

        [geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *array, NSError *error)

         {

            if (array.count > 0)

             {

                 // CLPlacemark类里的属性包含了详细的地址信息

                CLPlacemark *placemark = [array objectAtIndex:0];

                NSString *city = placemark.locality;

                NSLog(@"%@",city);

             }

            else if (error == nil && [array count] == 0)

             {

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

             }

            else if (error != nil)

             {

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

             }

 

         }];

 

 

博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3