如何在iphone中使用mapkit获取位置名称?

时间:2011-10-27 10:57:49

标签: iphone mapkit

我是iphone开发的新手,现在我面临着开发开发应用程序的问题,当用户在屏幕上点击两秒钟并获得用户位置名称时我需要获得坐标(lat,long),我得到了坐标,但我无法获取用户点击的用户位置名称。那么请帮助我吗?

1 个答案:

答案 0 :(得分:1)

在iOS 5+中使用CLGeocoder及其reverseGeocodeLocation:completionHandler:方法。

在您的情况下,您可能对areasOfInterest属性最感兴趣。

示例:

CLGeocoder* gc = [[CLGeocoder alloc] init];
double lat, lon; // get these where you will
[gc reverseGeocodeLocation:[[CLLocation alloc] initWithLatitude:lat longitude:lon] completionHandler:^(NSArray *placemarks, NSError *error) {
    for ( CLPlacemark* place in placemarks ) {
        if ( place.region )
            NSLog( @"%@", place.region );
        // throroughfare is street name, subThoroughfare is street number
        if ( place.thoroughfare )
            NSLog( @"%@ %@", place.subThoroughfare, place.thoroughfare );
        for ( NSString* aoi in place.areasOfInterest )
            NSLog( @"%@", aoi );
    }
}];
相关问题