Question

I have used CLLocationManager to get the current GPS coordinates of a user.

How would I use CLGeoCoder to convert these coordinates into just the current State the user is in?

Thanks.

Was it helpful?

Solution

Use the -reverseGeocodeLocation:completionHandler method, then inspect the administrativeArea property of the returned placemark.

In code:

/* Get a CLLocation into `location` */
CLGeocoder *gc = [[CLGeocoder alloc] init];
[gc reverseGeocodeLocation:location completionHandler:^(NSArray *placemark, NSError *error)
{
  if(!placemark)
  {
    /* handle error */
  }
  else
  {
    CLPlacemark *pm = placemark[0];
    NSLog(@"%@", pm.administrativeArea);
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top