IamRKhanna
IamRKhanna

Reputation: 228

GMSGeocoder iOS SDK - Not receiving callback on reverse geocoding

I am scrolling through each asset in an asset group and trying to retrieve locations from the existing data of the images used in Google Maps sdk 1.9.1. Here is the code that I wrote

-(NSString *) doRevGeoCodingForLocationWithLat:(double)lat AndLon:(double)lon {
__block NSString *finalAddress = nil;
GMSGeocoder *sharedInstance = [[GMSGeocoder alloc] init];
if (sharedInstance) {
    dispatch_semaphore_t sema = dispatch_semaphore_create(0);
    CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(lat, lon);
    GMSReverseGeocodeCallback handler = ^(GMSReverseGeocodeResponse *response, NSError *error) {
        if (!error && response) {
            NSLog(@"Mil gaya");
            GMSAddress *firstAddress = [response firstResult];
            NSString *formattedAddress = nil;
            if (firstAddress.locality)
                formattedAddress = [NSString stringWithString:firstAddress.locality];

            if (firstAddress.administrativeArea) {
                if (formattedAddress)
                    formattedAddress = [formattedAddress stringByAppendingFormat:@", %@", firstAddress.administrativeArea];
                else
                    formattedAddress = [NSString stringWithString:firstAddress.administrativeArea];
            }
            if (firstAddress.country) {
                if (formattedAddress)
                    formattedAddress = [formattedAddress stringByAppendingFormat:@", %@", firstAddress.country];
                else
                    formattedAddress = [NSString stringWithString:firstAddress.country];
            }
            if (formattedAddress) {
                finalAddress = [NSString stringWithString:formattedAddress];
            }
        }
        dispatch_semaphore_signal(sema);
    };

    [sharedInstance reverseGeocodeCoordinate:coordinate completionHandler:handler];
    dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
}
return finalAddress;
}

The problem is that the completionHandler callback is never called back from the SDK. I have setup the google APIs console and the demo app bundled with the sdk is working perfectly.

I read from the documentation that the completionHandler is called on main queue of the app. Could the problem be happening because this operation is happening on a concurrent queue that is enumerating through the assets?? Any help would be greatly appreciated.

Upvotes: 1

Views: 794

Answers (1)

Daij-Djan
Daij-Djan

Reputation: 50089

Arc is releasing your loyal Geocoder variable right away right now and no asynchronous calls can proceed.

As a test/ hack make the sharedInstance global so it is kept around.

Upvotes: 1

Related Questions