在MKMapkit中如何获取textfield或tableview中的当前位置详细信息

时间:2013-03-28 13:04:40

标签: iphone objective-c ipad ios6 iphone-5

RootViewController *objYourViewController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
CATransition* transition = [CATransition animation];
transition.duration = 1.0;
transition.type = kCATransitionPush;
transition.subtype = kCATransitionPush;
[self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
[self.navigationController pushViewController:objYourViewController animated:YES];

这用于指向当前位置。现在我想在textfield或tableview中获取当前位置详细信息,如果有人知道,请帮助我。

1 个答案:

答案 0 :(得分:1)

我使用了以下代码..

首先在MKReverseGeocoderDelegate文件中添加.h ..

MKReverseGeocoder文件中创建.h的对象后,如belolow ..

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/

我希望这对你有所帮助..