以下のコードを使用していました..
最初MKReverseGeocoderDelegate
に.h
ファイルに追加..
MKReverseGeocoder
以下のようなファイル内のオブジェクトを作成した後.h
..
MKReverseGeocoder *mkReverseGeocoder;
そして、UIButton
アクションイベントで次のように使用します
-(IBAction)btnFindMe_Clicked:(id)sender{
if(mkReverseGeocoder)
{
[mkReverseGeocoder autorelease];
}
mkReverseGeocoder = [[MKReverseGeocoder alloc] initWithCoordinate:[currLocation coordinate]];
[mkReverseGeocoder setDelegate:self];
[mkReverseGeocoder start];
}
そして、この以下のメソッドはデリゲートメソッドですMKReverseGeocoder
//mkreversegeocoder protocol methods
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error
{
[appDelegate hideLoadingView];
UIAlertView *alt=[[UIAlertView alloc]initWithTitle:@"Error" message:@"Try Again After Sometime" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alt show];
[alt release];
// NSLog(@"\n\n Error is %@",[error description]);
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark
{
[appDelegate hideLoadingView];
NSLog(@"\n\n Address Dict : %@",[[placemark addressDictionary] description]);
txtCity.text=[[placemark addressDictionary] objectForKey:@"City"];
txtState.text=[[placemark addressDictionary] objectForKey:@"State"];
txtAddress1.text=[[placemark addressDictionary] objectForKey:@"Street"];
txtAddress2.text=[[placemark addressDictionary] objectForKey:@"SubLocality"];
//[NSString stringWithFormat:@"%@", [[gpsTextView addressDictionary] description], ];
}
また、例を含むこのリンクを参照してください。ただし、別のコードです。上記は私のカスタムコードです... how-to-get-current-latitude-and-longitude-in-iphone/