简体   繁体   English

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

[英]Why am I unable to set pin address to annotation's subtitle?

Trying to set address of pin position to annotation subtitle if it == nil. 如果== nil,则尝试将引脚位置的地址设置为注释字幕。 But nothing happens. 但是什么也没发生。

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"];
                }

The thing that is going on with your code is that the geocoder is an asynchronous operation. 您的代码正在进行的事情是,地理编码器是异步操作。 Your pins are being placed before the completion of the geocode. 您的图钉将在地理编码完成之前放置。 Depending on how your code is set up you may be losing the reference to your pin before the geocode is complete. 根据您的代码设置方式,在地理编码完成之前,您可能会丢失对引脚的引用。 Try geocoding your placemark before you create the annotations. 在创建注释之前,请尝试对地标进行地理编码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM