我正在尝试找到当前位置,然后使用地理编码器查找城市,州。 这就是我所拥有的:
- (void)viewDidLoad
{
self.locationManager = [[[CLLocationManager alloc] init] autorelease];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
[locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
geoCoder = [[MKReverseGeocoder alloc] initWithCoordinate:newLocation.coordinate];
geoCoder.delegate = self;
[geoCoder start];
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark{
//NSLog(@"Reverse Geocoder completed");
MKPlacemark * myPlacemark = placemark;
NSString *city = [myPlacemark.addressDictionary objectForKey:(NSString*)kABPersonAddressCityKey];
NSString *state = [myPlacemark.addressDictionary objectForKey:(NSString*)kABPersonAddressStateKey];
location = [[NSString alloc] initWithFormat:@"%@,%@", city, state];
}
我测试了反向地理编码器,当我手动输入创建当前位置的坐标时,它工作正常:(50.4,-104.6)。但是,当我在“didUpdateToLocation”委托方法中使用断点运行此代码时,newLocation为我提供了一个37.3的坐标,-122.0是加利福尼亚州的库比蒂诺。我想我正在设置locationManager错误,所以任何想法?