将地址编码到iphone中的坐标中 [英] geocoding address into coordinates in iphone

查看:98
本文介绍了将地址编码到iphone中的坐标中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下代码将地址编码为坐标:

I am trying to geocode address into coordinates using following code:

CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    [geocoder geocodeAddressString:@"6138 Bollinger Road, San Jose, United States" completionHandler:^(NSArray* placemarks, NSError* error){
                     for (CLPlacemark* aPlacemark in placemarks)
                     {
                         // Process the placemark.
                         NSString *latDest1 = [NSString stringWithFormat:@"%.4f",aPlacemark.location.coordinate.latitude];
                         NSString *lngDest1 = [NSString stringWithFormat:@"%.4f",aPlacemark.location.coordinate.longitude];
                         lblDestinationLat.text = latDest1;
                         lblDestinationLng.text = lngDest1;
                     }
                 }];

我已经尝试了很多次但调试器从未进入块状态,我无法获得位置。有人可以帮我吗?

I have tried it many times but the debugger never enters the block and I am not able to get the location. Can someone please help me with it?

问候

Pankaj

Regards
Pankaj

推荐答案

好吧我发现了自己的错误。
代码是正确的,并且完美无缺。我一直在研究它是通过调试器,并试图弄清楚为什么调试器没有进入块。但是现在我发现调试器在那一刻没有进入块。获取位置值几乎不需要。它是异步完成的,所以我无法找到它,因为崩溃后没有值,我崩溃了。我已将代码发布块移动到块内部,现在一切正常。

All right I found my mistake. The code is correct and works perfect. All the while I was working on it was through debugger and was trying to figure out why the debugger did not enter the block. But now I have found out debugger does not enter the block at that moment. It takes little in getting the location values. It is done asynchronously so I was not able to find it and I was getting crash because of no values just after the crash. I have moved my code post block to inside the block and everything works fine for me now.

这篇关于将地址编码到iphone中的坐标中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆