iphone - 将地址地理编码为 iPhone 中的坐标

标签 iphone ios ios5 geocoding

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

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

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

问候
潘卡吉

最佳答案

好吧,我发现了我的错误。 代码是正确的并且工作完美。我一直在通过调试器处理它,并试图弄清楚为什么调试器没有进入 block 。但是现在我发现调试器在那一刻没有进入 block 。获取位置值几乎不需要。它是异步完成的,所以我无法找到它,并且由于崩溃后没有任何值而导致崩溃。我已将我的代码发布 block 移动到 block 内部,现在一切正常。

关于iphone - 将地址地理编码为 iPhone 中的坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10735981/

相关文章:

opengl-es - 如何将 OpenGL ES 纹理转换为 CIImage

iPhone 开发 - UIWebView 中的 SVG 图像

iphone - 我可以安全地将 UInt32 存储到 NSUInteger 吗?

ios - 线程 1 : EXC_BAD_INSTRUCTION when trying to write a message JSQMessagesViewController

ios - 进程启动失败 : failed to get the task for process 2847

ios - 类的实例未在 Swift 中打印其值

core-data - 使用属性搜索实体时的核心数据 SubEntitiesByName

iphone - 更改 UINavigationController 导航栏的动画

iOS Auto Layout Constraints - View Resize per 3.5 vs 4 inch screen

objective-c - NSURLRequest/NSURLConnection ios 5.0 v/s 早期版本