문제

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.

도움이 되었습니까?

해결책

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);
  }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top