Monday, March 18, 2013

Converting Longitude and Latitude to a Meaningful Address



This part of code is from Book , Vandad Nahavandipoor.


1. Declare a property of type CLGeocoder


    #import
   #import  
     @interface
     Converting_Meaningful_Addresses_to_Longitude_and_LatitudeViewController UIViewController
    @property (nonatomicstrongCLGeocoder *myGeocoder;
    @end 



2. In viewdidload

            CLLocation *location = [[CLLocation alloc] initWithLatitude:+38.4112810
longitude:-122.8409780f]; self.myGeocoder = [[CLGeocoder alloc] init];
[self.myGeocoder
reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {
if (error == nil && [placemarks count] > 0){
CLPlacemark *placemark = [placemarks objectAtIndex:0]; /* We received the results */
NSLog(@"Country = %@", placemark.country); 
NSLog(@"Postal Code = %@", placemark.postalCode);
NSLog(@"Locality = %@", placemark.locality);
}
else if (error == nil &&
[placemarks count] == 0){ NSLog(@"No results were returned.");
}
else if (error != nil){
NSLog(@"An error occurred = %@", error); }
}]; 

No comments:

Post a Comment