in MKMapkit how to get the current location detail in textfield or tableview

人走茶凉 提交于 2020-01-05 06:37:20

问题


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];

This is used to point the current location. Now i want to get the current location detail in textfield or tableview so please help me if any one know.


回答1:


i had use bellow code..

First Add MKReverseGeocoderDelegate in .h file..

after create object of MKReverseGeocoder in .h file like belolow..

MKReverseGeocoder *mkReverseGeocoder;

and then use it like bellow on your UIButton Action event

-(IBAction)btnFindMe_Clicked:(id)sender{
    if(mkReverseGeocoder)
    {
        [mkReverseGeocoder autorelease];
    }

    mkReverseGeocoder = [[MKReverseGeocoder alloc] initWithCoordinate:[currLocation coordinate]];

    [mkReverseGeocoder setDelegate:self];
    [mkReverseGeocoder start];
}

and this bellow methods are delegate methods of 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], ];
}

Also See this link with example but its another code.. above is my custom code... how-to-get-current-latitude-and-longitude-in-iphone/

i hope this is helpful to you..



来源:https://stackoverflow.com/questions/15682595/in-mkmapkit-how-to-get-the-current-location-detail-in-textfield-or-tableview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!