gpt4 book ai didi

iphone - iOS5 CLGeocoder

转载 作者:可可西里 更新时间:2023-11-01 06:26:08 25 4
gpt4 key购买 nike

我正在为 IOS5 开发一个 iPhone 应用程序。我目前正在使用位于 CoreLocation 框架内的 CLGeocoder 类。我无法弄清楚完成处理程序 block 是否在最后调用,在地理编码发生之后或同时调用。

我只知道完成处理程序 block 是在主线程上运行的。有谁知道完成处理程序 block 是在地理编码完成时运行还是在地理编码器在另一个线程上执行时完成手头任务的代码?

最佳答案

完成处理程序在地理编码器完成地理编码后运行。换句话说,它在地理编码任务完成时运行。它不是为了在地理编码器运行时完成一些其他任务。

完成处理程序包含地标和错误。如果地理编码成功,您将获得一个地标数组。否则,您会收到错误消息。

文档注释:

This method submits the specified location data to the geocoding server asynchronously and returns. Your completion handler block will be executed on the main thread. After initiating a forward-geocoding request, do not attempt to initiate another forward- or reverse-geocoding request.

Geocoding requests are rate-limited for each app, so making too many requests in a short period of time may cause some of the requests to fail. When the maximum rate is exceeded, the geocoder passes an error object with the value kCLErrorNetwork to your completion handler.

@interface MyGeocoderViewController ()

@property (nonatomic, strong) CLGeocoder *geocoder;

@end

@implementation MyGeocoderViewController

- (void)viewDidLoad
{
[super viewDidLoad];

// Create a geocoder and save it for later.
self.geocoder = [[CLGeocoder alloc] init];
}
- (void)geocodeAddress:(NSString *)addressString
{
// perform geocode
[geocoder geocodeAddressString:addressString
completionHandler:^(NSArray *placemarks, NSError *error) {

if ((placemarks != nil) && (placemarks.count > 0)) {
NSLog(@"Placemark: %@", [placemarks objectAtIndex:0]);
}
// Should also check for an error and display it
else {
UIAlertView *alert = [[UIAlertView alloc] init];
alert.title = @"No places were found.";
[alert addButtonWithTitle:@"OK"];
[alert show];
}
}];
}

@end

关于iphone - iOS5 CLGeocoder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10286398/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com