【发布时间】:2012-05-30 22:45:11
【问题描述】:
我正在尝试使用以下代码将地址地理编码为坐标:
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;
}
}];
我已经尝试了很多次,但调试器从不进入块,我无法获得位置。有人可以帮我吗?
问候
潘卡伊
【问题讨论】:
-
非常感谢,花了半天时间后,我从您的问题中得到了解决方案。因此,您的问题需要一个 UP 和 Star 标记。再次感谢。
-
如何将经度和纬度保存在此块外的变量中?因为我需要将它们传递给另一个控制器。
-
@user3722523 您必须在块外定义一个变量并将其标记为__block。现在您将能够访问块内的变量,并且可以将值保存到该变量中。
-
@pankaj 我正在使用 swift 并且 __block 不再存在。