0
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Override point for customization after app launch    
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];

    [window addViewForTouchPriority:viewController.view];

    if(self.locationManager==nil){
        locationManager=[[CLLocationManager alloc] init];

        locationManager.delegate=self;
        locationManager.purpose = @"We will try to tell you where you are if you get lost";
        locationManager.desiredAccuracy=kCLLocationAccuracyBest;
        locationManager.distanceFilter=500;
        self.locationManager=locationManager;
    }
    geoCoder = [[CLGeocoder alloc] init];

    if([CLLocationManager locationServicesEnabled]){
        [self.locationManager startUpdatingLocation];          
    }

    return YES;
}

-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    lati = [[NSString alloc] initWithFormat:@"%+.6f", newLocation.coordinate.latitude];
    NSLog(@"address:%@",lati);

    longi = [[NSString alloc] initWithFormat:@"%+.6f", newLocation.coordinate.longitude];
    NSLog(@"address:%@",longi);

    CLLocationCoordinate2D coord;
    coord.latitude = [lati doubleValue];
    coord.longitude = [longi doubleValue];


    [geoCoder reverseGeocodeLocation: newLocation completionHandler: ^(NSArray *placemarks, NSError *error)
     {

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

         //String to hold address
         NSString *locatedAt = [[placemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "];

         //Print the location to console
         NSLog(@"I am currently at %@",locatedAt);

         address = [[NSString alloc]initWithString:locatedAt];    
         NSLog(@"address:%@",address);
     }];
}

I am using above code to get address by giving latitude and longitude, but control is not entering in to geocoder method, it skips it. Can anybody help me in it.

Thanks in advance.

janusfidel
  • 8,036
  • 4
  • 30
  • 53
iPhone Programmatically
  • 1,211
  • 2
  • 22
  • 54

2 Answers2

0

It doesn't matter, control does not enter in the method, but it works, note the output it will work.

iPhone Programmatically
  • 1,211
  • 2
  • 22
  • 54
0

that is normal, because the code inside the reverseGeocodeLocation is execute inside a block. The execution of the code inside a block occurs in another thread, so is not execute in the main thread, that's why the control don't enter inside the geocoder method.

Max_Power89
  • 1,710
  • 1
  • 21
  • 38