Thursday, 24 October 2013

get Curernt address using CLGeocoder

So many applications use corelocation services to get location update and get curent location .So we here use CLGeocoder to get current city ,administritive area,country etc,for that you have to create CLLocation object by self ,or use got from the location update method find the code here.


 CLLocation *location  = [[CLLocation alloc] initWithLatitude:
23.03005981 longitude:
72.54624939];


 CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    [geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {
        CLPlacemark *placemark;
        if(!error){
            placemark = [placemarks objectAtIndex:0];
            [ApplicationPreferences setCurrentLocation:placemark.locality];
            [ApplicationPreferences setCurrentAddress:[NSString stringWithFormat:@"%@%@%@",placemark.locality,@",",placemark.administrativeArea]];
            if(self.nowLoad==TRUE){
                [self createBackgroundThread];
            }
        }
        else{
            if(DEBUG_MODE){
                NSLog(@"There was a reverse geocoding error\n%@",
                      placemark.locality);
            }
        }
        
        
        
    }];

No comments:

Post a Comment