Note that there are some explanatory texts on larger screens.

plurals
  1. POHandling the Async event in CLGeocoder (iOS5)
    primarykey
    data
    text
    <p>I am trying to reverse geocode a location, I have managed todo this but I have hit a slight snag which is preventing me from completing it. I think I know WHAT it's doing and WHY, but I am not able to figure out a way to get around it yet. (I am using ARC and iOS5)</p> <p>The problem occurs when I execute the following code in my init method ...</p> <pre><code>[self setSubtitle: [dateString stringByAppendingString: self.city ] ]; </code></pre> <p>self.city is returning back a null value, I am pretty sure this is because the init method completes WAY before the geocoder can go and do it's thing.</p> <p>So my question is, how can I handle this situation? I assume sitting and waiting for the geocoder to complete its work and freezing the app until such time isn't the way to go?</p> <pre><code>#import "MapPoint.h" @implementation MapPoint @synthesize coordinate, title, dateAdded, subtitle, city; -(id)initWithCoordinates:(CLLocationCoordinate2D)c title:(NSString *)t { self = [super init]; if (self) { coordinate = c; [self setTitle: t]; [self setCurrentCity: [[CLLocation alloc] initWithLatitude:c.latitude longitude:c.longitude]]; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setTimeStyle:NSDateFormatterNoStyle]; [formatter setDateStyle:NSDateFormatterLongStyle]; [self setDateAdded: [[NSDate alloc] init]]; NSString *dateString = [formatter stringFromDate: [self dateAdded]]; [self setSubtitle: [dateString stringByAppendingString: self.city ] ]; } return self; } -(void)setCurrentCity: (CLLocation *)loc { CLGeocoder *reverseGeo; if (!reverseGeo) { reverseGeo = [[CLGeocoder alloc] init]; } [reverseGeo reverseGeocodeLocation: loc completionHandler: ^(NSArray *placemarks, NSError *error) { if ([placemarks count] &gt; 0) { CLPlacemark *topResult = [placemarks objectAtIndex:0]; self.city = [NSString stringWithFormat:@"%@", [topResult locality]]; } }]; } @end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload