CLLocationManager と CLGeocoder を使用して iPhone ユーザーの場所を特定しようとしています。
私の CLLocationManager はうまく機能しているようですが、残念ながら CLGeocoder は私がやりたいことをしません。
一部のコードの抜粋:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
[self.locationManager stopUpdatingLocation];
NSLog(@"Location updated to: %@",newLocation);
[self.geocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
NSLog(@"Reverse geocoding finished");
self.currentPlacemark = [placemarks objectAtIndex:0];
NSLog(@"%@",self.currentPlacemark.locality);
NSLog(@"%@",self.currentPlacemark.ISOcountryCode);
}];
}
- (void)getCurrentLocation {
NSLog(@"Determining current location");
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
[self.locationManager startUpdatingLocation];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self getCurrentLocation];
}
self.currentPlacemarkはCLPlacemarkオブジェクトです。
self.geocoderはCLGeocoderオブジェクトです。
self.locationManagerはCLLocationManagerオブジェクトです。
私は何が欠けていますか?なぜこれが機能しないのですか?私は正直に何時間も費やし、ゆっくりと自暴自棄になり始めています…</p>