0
我试图确定使用CLLocationManager和CLGeocoder了iPhone用户的位置。CLGeocoder不返回任何
我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对象。
我错过了什么?为什么这不起作用? 老实说,我花了几个小时,我慢慢开始变得绝望......
你能更具体地说“不做我想做的事”吗?特别是,它在做什么?还是不行? – gaige
当然,抱歉在这一点不清楚:completionHandler块永远不会被输入(或换句话说:我从来没有看到日志语句“反向地理编码已完成”) – Patrick
你有alloc和初始化你的地理编码器吗? –