【发布时间】:2016-02-16 13:33:06
【问题描述】:
我需要从 2 个坐标中获取城市名称(我正在使用 GMSGeoCoder -reverseGeocodeCoordinate: completionHandler: 方法),然后对对象进行比较。
问题是该方法在后台线程上运行(而不是在主线程中),当我尝试比较(使用if 语句)对象(userCity 和storeCity-两者都是NSString ) 仍然为零。
我的代码:
//Checking user's city
__block NSString *userCity;
[[GMSGeocoder geocoder]reverseGeocodeCoordinate:self.locationManager.location.coordinate completionHandler:^(GMSReverseGeocodeResponse *response, NSError *error) {
if (error) {
NSLog(@"%@",[error description]);
}
userCity=[[[response results] firstObject] locality];
}];
//Checking store's city
__block NSString *storeCity;
[[GMSGeocoder geocoder]reverseGeocodeCoordinate:arounder.radiusCircularRegion.center completionHandler:^(GMSReverseGeocodeResponse *response, NSError *error) {
if (error) {
NSLog(@"%@",[error description]);
}
arounderCity=[[[response results] firstObject] locality];
}];
if ([userCity isEqualToString:arounderCity]) {
return YES;
}
有什么想法吗?谢谢!
【问题讨论】:
-
是的,等待块然后继续!
-
@Daij-Djan 这基本上就是我想做的,但我该怎么做呢?可以给我一个代码示例吗?
-
我写了一个。请注意我是内联写的,可能有较小的错别字,但它会给你逻辑
标签: ios objective-c google-maps-sdk-ios