Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to get complete address from latitude/logitude

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 547
    Comment on it

    Let's find out the latitude/longitude first to find out the address.
    1) Add CoreLocation.framework under Targets -> Build Phases -> Link Binary With Libraries
    2) Import in your view controller where you need to find out the address.
    3) Add CLLocationManagerDelegate to Interface(.h file) of your view controller.
    4) Create objects in Interface(.h file) like below
    @property (nonatomic, strong) CLLocationManager *locationManager; @property (nonatomic, strong) CLGeocoder *geoCoder; 5) Now in implementation(.m file) class do the following- Call below method in ViewDidLoad.

    1. - (void) findLocation{
    2. _geoCoder = [[CLGeocoder alloc] init];
    3.  
    4. _locationManager = [[CLLocationManager alloc]init];
    5. _locationManager.delegate = self;
    6. _locationManager.distanceFilter = kCLDistanceFilterNone;
    7. _locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
    8. [_locationManager startUpdatingLocation];
    9.  
    10. }

    Add delegate method from CLLocationManagerDelegate.

    1. - (void)locationManager:(CLLocationManager *)manager
    2. didUpdateToLocation:(CLLocation *)newLocation
    3. fromLocation:(CLLocation *)oldLocation
    4. { //Stop updating location to save battery power
    5. [_locationManager stopUpdatingLocation];
    6.  
    7. [self getLocationName];
    8.  
    9. }

    Add method getLocationName to get the address

    1. - (void)getLocationName{
    2.  
    3. [_geoCoder reverseGeocodeLocation:_locationManager.location completionHandler:
    4. ^(NSArray *placemarks, NSError *error) {
    5.  
    6. CLPlacemark *placemark = [placemarks objectAtIndex:0];
    7. //String to find out any value from complete address
    8. NSString *state = [placemark.addressDictionary valueForKey:@"State"] ;
    9. NSLog(@"State name is: %@",state);
    10.  
    11. NSString *city = [placemark.addressDictionary valueForKey:@"City"] ;
    12. NSLog(@"City name is: %@",city);
    13. // complete address
    14. NSLog(@"located at %@",placemark.addressDictionary);
    15.  
    16. }];
    17.  
    18.  
    19. }

    Output:

    State name is: Uttarakhand
    City name is: Dehra Dun
    located at {
    City = "Dehra Dun";
    Country = India;
    CountryCode = IN;
    FormattedAddressLines = (
    "National Highway 72",
    "Dehra Dun",
    Uttarakhand,
    India
    );
    Name = "National Highway 72";
    State = Uttarakhand;
    Street = "National Highway 72";
    Thoroughfare = "National Highway 72";
    }

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: