Pregunta

I'm receiving a list of latitude and longitudes by the web service and geocoding then to get the full address. The problem is that after some time, they become null, and the geocoder stop working! Can somebody help me?

Here's the code that I'm using to get the address:

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

Thanks!

¿Fue útil?

Solución

Check the error passed in to the block, probably you are sending to many request and the rate limit is reached.

There is rate limit for reverseGeocodeLocation:completionHandler:

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top