为什么我无法将图钉地址设置为注释的字幕?



如果 == nil,则尝试将引脚位置的地址设置为注释字幕。但什么也没发生。

if (myAnnotation.subtitle == nil)
                    [self.geoCoder reverseGeocodeLocation: locationManager.location completionHandler: 
                     ^(NSArray *placemarks, NSError *error) {
                         CLPlacemark *placemark = [placemarks objectAtIndex:0];
                         NSString *locatedAt = [[placemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "];  
                         myAnnotation.subtitle = locatedAt;
                     }];   
                else {
                    myAnnotation.subtitle = [[ann objectAtIndex:i] objectForKey:@"Address"];
                }

您的代码正在发生的事情是地理编码器是一个异步操作。您的图钉是在地理编码完成之前放置的。根据代码的设置方式,您可能会在地理编码完成之前丢失对图钉的引用。在创建注记之前,请尝试对地标进行地理编码。

最新更新