iOS把经纬度反转为位置信息(街道名等)

最近做应用用到定位,位置信息可以很容易由CLLocationManager得到(得到的经纬度在中国有偏移,需要纠偏)。但是怎么把特定经纬度的位置信息得到呢,查看了一下资料,发现了CLGeocoder这个类,可以把经纬度反转为位置信息。代码如下:

-(void)reverseGeocodeForLocation:(CLLocationCoordinate2D)coordinate

{

    CLLocation *loacation = [[[CLLocation alloc] initWithLatitude:coordinate.latitudelongitude:coordinate.longitude] autorelease];

    CLGeocoder *geoCoder = [[[CLGeocoder alloc] init] autorelease];

    [geoCoder reverseGeocodeLocation:loacation completionHandler:^(NSArray *placemarks, NSError *error)

    {

         //得到的数组placemarks就是CLPlacemark对象数组,这里只取第一个就行

         CLPlacemark *mark = nil;

         if([placemarks count] > 0){

             id tempMark = [placemarks objectAtIndex:0];

             if([tempMark isKindOfClass:[CLPlacemark class]])

             {

                 mark = tempMark;

             }

             //具体业务逻辑,CLPlacemark的属性有很多,包括了街道名等相关属性

         }             

     }];

}

 

posted on 2013-05-29 22:54  VicStudio  阅读(1030)  评论(0编辑  收藏  举报