Tuesday, December 15, 2015

Get User's City thought latitude and longitude in iOS



#pragma mark - Get User's City

+(void)getCityOfUser{
    CLLocation *LocationAtual = [[CLLocation allocinitWithLatitude:@"latitude"longitude:@"longitude"];
    
    CLGeocoder *geocoder = [[CLGeocoder allocinit] ;
    [geocoder reverseGeocodeLocation:LocationAtual
                   completionHandler:^(NSArray *placemarks, NSError *error) {
                       NSLog(@"reverseGeocodeLocation:completionHandler: Completion Handler called!");
                       
                       if (error){
                           NSLog(@"Geocode failed with error: %@", error);
                           return;
                           
                       }
                        CLPlacemark *placemark = [placemarks objectAtIndex:0];
                       
                       NSLog(@"placemark.ISOcountryCode %@",placemark.ISOcountryCode);
                       NSLog(@"placemark.country %@",placemark.country);
                       NSLog(@"placemark.postalCode %@",placemark.postalCode);
                       NSLog(@"placemark.administrativeArea %@",placemark.administrativeArea);
                       NSLog(@"placemark.locality %@",placemark.locality);
                       NSLog(@"placemark.subLocality %@",placemark.subLocality);
                       NSLog(@"placemark.subThoroughfare %@",placemark.subThoroughfare);
                       
                   }];

}

No comments:

Post a Comment