那么有一个更简单的方法,您可以使用反向 GeocodeLocation 来获取该地点的信息。你必须知道这在每个城市都不会起作用。有关更多信息,请查看 Apple 的CLGeocoder 类参考和地理编码位置数据文档。
所以你可以创建和处理服务的对象
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
@interface locationUtility : NSObject<CLLocationManagerDelegate>{
CLLocationManager *locationManager;
CLPlacemark *myPlacemark;
CLGeocoder * geoCoder;
}
@property (nonatomic,retain) CLLocationManager *locationManager;
@end
和实施
#import "locationUtility.h"
@implementation locationUtility
@synthesize locationManager;
#pragma mark - Init
-(id)init {
NSLog(@"locationUtility - init");
self=[super init];
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
[locationManager startMonitoringSignificantLocationChanges];
geoCoder= [[CLGeocoder alloc] init];
return self;
}
- (void) locationManager:(CLLocationManager *) manager didUpdateToLocation:(CLLocation *) newLocation
fromLocation:(CLLocation *) oldLocation {
[geoCoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
CLPlacemark *placemark = [placemarks objectAtIndex:0];
myPlacemark=placemark;
// Here you get the information you need
// placemark.country;
// placemark.administrativeArea;
// placemark.subAdministrativeArea;
// placemark.postalCode];
}];
}
-(void) locationManager:(CLLocationManager *) manager didFailWithError:(NSError *) error {
NSLog(@"locationManager didFailWithError: %@", error.description);
}
@end