2
我是新的iphone開發,現在我面臨着開發一個應用程序的問題,在這個應用程序中,當用戶在屏幕上點擊兩秒鐘並獲取用戶位置名稱時,我需要獲得座標(lat,long)但我無法獲取用戶點擊的用戶位置名稱。那麼好心地幫助我呢?如何在iphone中使用mapkit獲取位置名稱?
我是新的iphone開發,現在我面臨着開發一個應用程序的問題,在這個應用程序中,當用戶在屏幕上點擊兩秒鐘並獲取用戶位置名稱時,我需要獲得座標(lat,long)但我無法獲取用戶點擊的用戶位置名稱。那麼好心地幫助我呢?如何在iphone中使用mapkit獲取位置名稱?
在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);
}
}];
你是如何定義的名字嗎?地址?商人? –
我需要當前的位置名稱,就像if'll點擊學校只是說,並作爲迴應我會得到具體的學校名稱,這可能嗎?怎麼可以? – Aleem