0

Trying to set address of pin position to annotation subtitle if it == 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"];
                }
Matt
  • 22,721
  • 17
  • 71
  • 112
Pavel Kaljunen
  • 1,291
  • 2
  • 26
  • 53
  • 1
    Are you trying to reverse geocode a lot of pins on a map? If so I don't think that it's designed for that many operations. Apple says in the docs "Send at most one geocoding request for any one user action." – jonusx Jun 05 '12 at 15:22
  • Yes, a lot of pins. Ok, thank you for that! – Pavel Kaljunen Jun 05 '12 at 15:36

1 Answers1

0

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.

jonusx
  • 139
  • 3