我收到了网络服务和地理编码的纬度和经度列表,然后获取完整地址。 问题是,经过一段时间后,它们变为空,地理编码器停止工作! 有人可以帮帮我吗?
以下是我用来获取地址的代码:
-(void)getAddressArray:(void (^)(id response))completion{
for (int i=0; i<[favoritos count]; i++) {
double latitude = [[[favoritos valueForKey:@"latitude"] objectAtIndex:i] doubleValue];
double longitude = [[[favoritos valueForKey:@"longitude"] objectAtIndex:i] doubleValue];
CLLocationCoordinate2D location = CLLocationCoordinate2DMake(latitude, longitude);
CLLocation * locationAtual = [[CLLocation alloc]initWithLatitude:location.latitude longitude:location.longitude];
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder reverseGeocodeLocation:locationAtual completionHandler:^(NSArray *placemarks, NSError *error) {
NSDictionary *dicAddress;
CLPlacemark *place = [placemarks firstObject];
if (placemarks) {
NSLog(@"%@",place.addressDictionary);
if ([place.addressDictionary valueForKey:@"Thoroughfare"] == [NSNull null] || ![place.addressDictionary valueForKey:@"Thoroughfare"]) {
dicAddress = @{@"id":[[favoritos objectAtIndex:i] valueForKey:@"id"],@"address":@"Endereço não encontrado!",@"complemento":[[favoritos objectAtIndex:i] valueForKey:@"references"],@"number":[[favoritos valueForKey:@"numero"] objectAtIndex:i],@"name":[[favoritos valueForKey:@"name"] objectAtIndex:i], @"latitude":[[favoritos valueForKey:@"latitude"] objectAtIndex:i], @"longitude":[[favoritos valueForKey:@"longitude"] objectAtIndex:i]};
}
[address addObject:dicAddress];
if ([address count] == [favoritos count])
completion(address);
}
}];
}
谢谢!
答案 0 :(得分:1)
检查传入块的错误,可能是您发送了很多请求并达到了速率限制。
reverseGeocodeLocation:completionHandler:
地理编码请求对每个应用都是速率限制的,所以制作太多了 短时间内的请求可能会导致一些请求 失败。超过最大速率时,地理编码器会传递错误 具有值kCLErrorNetwork的对象到您的完成处理程序。