0

My question is, why are poiCoordinate's latitude and longitude properties coming out 0, 0 when addressTF.text has a very sensible address string, for example "1 Infinite Loop, Cupertino, CA 95014"?

//HomeViewController.m

@implementation HomeViewController

CLLocationCoordinate2D poiCoordinate;

-(void)performStringGeocode
{
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    [geocoder geocodeAddressString:_addressTF.text completionHandler:^(NSArray *placemarks, NSError *error)
    {
        if (error)
        {
            NSLog(@"Geocode failed with error: %@", error);
            return;
        }
    CLPlacemark *placemark = [placemarks firstObject]; //Line A
    poiCoordinate = placemark.location.coordinate;     //Line B
    }];
}
Rachel Q
  • 23
  • 1
  • 5
  • The completionHandler block runs asynchronously meaning the performStringGeocode method doesn't wait for it to finish and returns immediately (before poiCoordinate is set). You'll need to redesign the code a bit. What are you doing with poiCoordinate after calling this method? See [this answer by Joshua Weinberg](http://stackoverflow.com/a/8432418/467105) for one approach. –  Jan 11 '14 at 03:06
  • Thank you. poiCoordinates are sent to the next view and used in an MKCoordinateRegion object – Rachel Q Apr 14 '14 at 21:09

0 Answers0