Pergunta

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.

Foi útil?

Solução

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);
  }
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top