我实际上使用这段代码来获取完整的位置信息:
@property (nonatomic,strong) CLPlacemark *placemark;
@property (strong) CLLocationManager *gps;
@property (strong) CLGeocoder *geocoder;
- (void)viewDidLoad
{
[super viewDidLoad];
gps = [[CLLocationManager alloc] init];
geocoder = [[CLGeocoder alloc] init];
gps.delegate = self;
gps.desiredAccuracy = kCLLocationAccuracyBest;
[gps startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
[geocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
if (error == nil && [placemarks count] > 0) {
placemark = [placemarks lastObject];
aLabel.text = [NSString stringWithFormat:@"%@ %@\n%@ %@\n%@",
placemark.thoroughfare,
placemark.subThoroughfare,
placemark.postalCode,
placemark.locality,
placemark.country];
} else {
NSLog(@"%@", error.debugDescription);
}
}];
}
但是如果需要,您可以使用其他CLPlacemark属性来获取更多信息:
来自CLPlacemark.h:
@property (nonatomic, readonly) NSString *name;
@property (nonatomic, readonly) NSString *thoroughfare;
@property (nonatomic, readonly) NSString *subThoroughfare;
@property (nonatomic, readonly) NSString *locality;
@property (nonatomic, readonly) NSString *subLocality;
@property (nonatomic, readonly) NSString *administrativeArea;
@property (nonatomic, readonly) NSString *subAdministrativeArea;
@property (nonatomic, readonly) NSString *postalCode;
@property (nonatomic, readonly) NSString *ISOcountryCode;
@property (nonatomic, readonly) NSString *country;
@property (nonatomic, readonly) NSString *inlandWater;
@property (nonatomic, readonly) NSString *ocean;
@property (nonatomic, readonly) NSArray *areasOfInterest;