【问题标题】:in MKMapkit how to get the current location detail in textfield or tableview在 MKMapkit 如何在文本字段或表格视图中获取当前位置详细信息
【发布时间】:2021-11-08 13:20: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];

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

【问题讨论】:

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


    【解决方案1】:

    我用过下面的代码..

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

    .h 文件中创建MKReverseGeocoder 的对象后,如下所示..

    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/

    【讨论】:

    • @vishnu 请参阅此链接以及教程.. edumobile.org/iphone/miscellaneous/… :)
    • 帕拉斯乔希。您能帮帮我吗?我无法获取当前位置...我需要当前位置作为 tableview 中的默认值。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-30
    • 1970-01-01
    • 1970-01-01
    • 2012-06-02
    • 1970-01-01
    相关资源
    最近更新 更多