Обратное геокодирование в iPhone:
Первое добавление <MobileCoreServices/MobileCoreServices.h>
framework.
-(void)CurrentLocationIdentifier
{
//---- For getting current gps location
CLLocationManager *locationManager;
CLLocation *currentLocation;
locationManager = [CLLocationManager new];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
}
Обратное геокодирование для получения сведений о месте с использованием местоположения GPS.
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
currentLocation = [locations objectAtIndex:0];
[locationManager stopUpdatingLocation];
CLGeocoder *geocoder = [[CLGeocoder alloc] init] ;
[geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error)
{
if (!(error))
{
CLPlacemark *placemark = [placemarks objectAtIndex:0];
NSLog(@"\nCurrent Location Detected\n");
NSLog(@"placemark %@",placemark);
NSString *locatedAt = [[placemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "];
NSString *Address = [[NSString alloc]initWithString:locatedAt];
NSString *Zipcode = [[NSString alloc]initWithString:placemark.postalCode];
NSLog(@"%@",Zipcode);
}
else
{
NSLog(@"Geocode failed with error %@", error); // Error handling must required
}
}];
}
Длябольше деталей, чтобы получить от GPS:
placemark.region
placemark.country
placemark.locality
placemark.name
placemark.ocean
placemark.postalCode
placemark.subLocality
placemark.location