reverseGeocodeLocation's completion Handler not getting called

536 Views Asked by At

I have written my code to get the current location of the user as follows-

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations{
CLLocation *currentLocation=[locations lastObject];
if (currentLocation!=nil) {
    _cityTextField.text=[NSString stringWithFormat:@"%f",currentLocation.coordinate.latitude];
    _locationTextField.text=[NSString stringWithFormat:@"%f",currentLocation.coordinate.longitude];
}

[geoCoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray<CLPlacemark *> *placeMarks, NSError *error){
    if (error==nil && [placeMarks count]>0) {
        placeMark=[placeMarks lastObject];
        _cityTextField.text=[NSString stringWithFormat:@"%@",placeMark.administrativeArea];
        _locationTextField.text=[NSString stringWithFormat:@"%@",placeMark.locality];
        [location stopUpdatingLocation];
    }
    else{
        NSLog(@"%@",error.debugDescription);
    }
}];

I am able to get the value of latitude and longitude in my text fields.But when the pointer reaches reverseGeocodeLocation method, it does not execute the completion handler and directly reaches at the end. Can anyone please point out my mistake. Thanks

0

There are 0 best solutions below