2012-03-24 124 views
0

我想知道如何獲取用戶當前的地址名稱。我已經找到了它的座標,但我需要找到用戶當前城市的名稱。使用Google API更好嗎,還是應該使用MKPlacemark來找到它?我看到MKReverseGeocoding在iOS 5.0中已棄用。請幫助一些簡單的教程或只是你的經驗。iOS獲取當前地址名稱 - mkplacemark?

回答

3

我是用戶無論使用什麼方法,你所感興趣的是找到位置的詳細信息。

您可以使用多種方法,具體取決於您得到的結果。

1]嘗試MKReverseGeocoder(然而,MapKit框架使用谷歌的服務,提供地圖數據。)

2]可以使用谷歌API來獲取結果。

如果您正在獲取MKReverseGeocoder棄用ypu可以使用CLGeocoder。

CLGeocoder *geocoder=[[CLGeocoder alloc]init]; 
     [geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks,NSError *error) 
     { 
      if([placemarks count]>0){ 
       CLPlacemark *result=[placemarks objectAtIndex:0]; 
       NSString *city=[NSString stringWithFormat:@"%@",[result locality]]; 
} 
];