簡體   English   中英

如何在iPhone中使用Mapkit獲取位置名稱?

[英]How to get location name using mapkit in iphone?

我是iphone開發的新手,現在我在開發開發應用程序時遇到問題,當用戶在屏幕上輕按兩秒鍾並需要獲取用戶位置名稱時,我需要獲取坐標(緯度,經度),但我得到了坐標,但是我無法獲取用戶點擊的用戶位置名稱。 那么請幫我嗎?

在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 );
    }
}];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM