Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

i write code of CLGecoder and the code are

-(NSString *)GetCurrentAddress:(CLLocation *)Location
{
  __block NSString  *locatedaddress;
    CLGeocoder *Gecoder=[[CLGeocoder alloc]init];
    [Gecoder reverseGeocodeLocation: Location completionHandler: 
     ^(NSArray *placemarks, NSError *error) {

         //Get address
         CLPlacemark *placemark = [placemarks objectAtIndex:0];

         NSLog(@"Placemark array: %@",placemark.addressDictionary );

         //String to address
       locatedaddress = [[placemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "];

         //Print the location in the console
         NSLog(@"Currently address is: %@",locatedaddress);


     }];
    return locatedaddress;
}

Problem is locatedaddress inside The completionHandler Has Value But Outside Is Not ? Any One Can Help Me ? Thanks In Advance.

share|improve this question

1 Answer 1

The geocoder is asynchronous -- which by definition means you cannot get the result immediately. You must use the completion handler to do whatever you want to do with the result.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.