CLLocationManager how to get full city or state name
I am using the CLLocationManager class in my iPad app to get the current location.
I am using below code to get address information,
- (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 the Details as shown 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 the name of the city, but not the full name like North Carolina, only NC.
when my clients used an app in the US, instead of a full name like "North Carolina" they get NC, St. Charles gets St. Charles ETC.
Is there a way to get the full names?
+3
source to share
1 answer
The following code, which returns all these details in 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);
}
}];
}
Let this help.
+6
source to share