Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Finding address from latitude longitude in ios using CLGeocoder

    • 0
    • 2
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 2.59k
    Comment on it

    CoreLocation framework of iOS provides method for finding address of a location using its latitude and longitude (also known as ReverseGeocoding). Following code snippet explains how to use it :

        CLLocation *location = targetlocation;
        CLGeocoder *geocoder = [[CLGeocoder alloc] init];
        [geocoder reverseGeocodeLocation:location
                       completionHandler:^(NSArray *placemarks, NSError *error) {
                           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(@"lat %f  long %f",placemark.location.coordinate.latitude,placemark.location.coordinate.longitude);
                           NSLog(@"placemark.name =%@",placemark.name);
                           NSLog(@"placemark.locality =%@",placemark.locality);
                           NSLog(@"placemark.Thoroughfare =%@",placemark.thoroughfare);
                           NSLog(@"placemark.subLocality =%@",placemark.subLocality);
    

    It makes an asynchronous request to fetch the information and the information fetched can be used from within the block. We can get and use different properties of the address of the location as can be seen in the code above.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: