5

i am using CLLocationManager class in my iPad App to get current location.

i am using below code to get Address details,

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    NSUserDefaults *oIsLocation = [NSUserDefaults standardUserDefaults];
    if([oIsLocation boolForKey:@"IsLocation"])
    {
        NSTimeInterval locationAge = -[newLocation.timestamp timeIntervalSinceNow];
        if (locationAge > 5.0) return;

        if (newLocation.horizontalAccuracy < 0) return;

        if (bestEffortAtLocation == nil || bestEffortAtLocation.horizontalAccuracy > newLocation.horizontalAccuracy)
        {
            if(bestEffortAtLocation.coordinate.latitude != newLocation.coordinate.latitude && bestEffortAtLocation.coordinate.longitude != newLocation.coordinate.longitude)
            {
                [self saveLocation:newLocation];
                self.bestEffortAtLocation = newLocation;
                [self saveUserLocation];
            }
        }
    }
}

i am doing reverse geocoding to get Details as below:

                       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);

placemark.locality gives city name but not Full name like North Carolina only NC.

when my clients used app in USA, instead of full name like 'North Carolina' they get NC,Saint Charles get St. Charles ETC.

is there any way to get full names?

user2813740
  • 517
  • 1
  • 7
  • 29

1 Answers1

7

Following code which returns all that details into CLPlacemark.

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{

    CLGeocoder * geoCoder = [[CLGeocoder alloc] init];
    [geoCoder reverseGeocodeLocation:newLocation
                   completionHandler:^(NSArray *placemarks, NSError *error) {
                       for (CLPlacemark *placemark in placemarks) {

                           NSLog(@"%@",[placemark locality]);

                           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);

                       }
                   }];
}

May this helps lot.

Nimit Parekh
  • 16,776
  • 8
  • 50
  • 72
  • 1
    yeah i am doing in my [self saveLocation:newLocation]; method. i mentioned i am getting all required details..... but instead of full name of City like Saint Charles i am getting as St Charles. i need full name. place mark.locality gives city name. from india i could not make out but when Client reported some issue i got problem is i am not getting Full name of City.... is there any way – user2813740 Jul 29 '15 at 16:58
  • @user2813740 did you get a solution for this – Nassif May 04 '21 at 08:32