我用过下面的代码..
首先添加文件MKReverseGeocoderDelegate
...h
MKReverseGeocoder
在文件中创建对象后,.h
如下所示..
MKReverseGeocoder *mkReverseGeocoder;
然后在您的UIButton
Action 事件中像下面一样使用它
-(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/