gpt4 book ai didi

ios - GMSGeocoder iOS SDK - 没有收到反向地理编码的回调

转载 作者:行者123 更新时间:2023-11-29 12:31:30 26 4
gpt4 key购买 nike

我正在滚动浏览 Assets 组中的每个 Assets ,并尝试从 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 回调。我已经设置了 google APIs 控制台,并且与 sdk 捆绑在一起的演示应用程序运行良好。

我从文档中了解到在应用程序的主队列上调用了 completionHandler。问题是否会发生,因为此操作是在通过 Assets 枚举的并发队列上发生的?任何帮助将不胜感激。

最佳答案

Arc 正在立即释放您忠实的 Geocoder 变量,并且无法进行任何异步调用。

作为测试/hack,将 sharedInstance 设置为全局,以便保留它。

关于ios - GMSGeocoder iOS SDK - 没有收到反向地理编码的回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27545800/

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