我正在滚动浏览资产组中的每个资源,并尝试从Google Maps sdk 1.9.1中使用的图像的现有数据中检索位置。这是我写的代码
-(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;
}
问题是completionHandler回调从SDK中回调从不。 我已经设置了谷歌API控制台,与sdk捆绑在一起的演示应用程序运行正常。
我从文档中读到,在应用程序的主队列上调用了completionHandler。问题是否会发生,因为此操作发生在通过资产枚举的并发队列上? 任何帮助将不胜感激。
答案 0 :(得分:1)
Arc正在立即释放您忠诚的Geocoder变量,并且不会进行任何异步调用。
作为测试/ hack使sharedInstance全局化,因此它保持不变。