【发布时间】:2015-01-03 09:43:55
【问题描述】:
我正在实现一个地理定位代码,这意味着我想将一个地址作为一个字符串,然后以 CLCoordinate 的形式返回一个位置。我收到了这个奇怪的错误代码,其他人似乎没有看到。
kCLErrorDomain 错误 8
我没有地图,因为我只想从地址字符串中获取坐标。然后稍后将此坐标用于程序的另一部分。我觉得我错过了什么。感谢您的所有帮助!
@interface ViewController () <CLLocationManagerDelegate, UISearchBarDelegate>
@property (strong, nonatomic) IBOutlet UISearchBar *BarSearch;
@property (strong,nonatomic) CLGeocoder *Geocoder;
@property (strong,nonatomic) CLLocationManager *locationManager;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.locationManager = [[CLLocationManager alloc]init];
self.locationManager.delegate = self;
//Check to see if they have Authorization to use to use location servieces
if ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)])
{
[self.locationManager requestAlwaysAuthorization];
}
[self.locationManager startUpdatingLocation];
//Setup UISearch Bar
self.BarSearch.delegate=self;
}
程序确实进入了这个方法,但只是返回这个错误: kCLErrorDomain 错误 8
-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
self.Geocoder = [[CLGeocoder alloc]init];
[self.Geocoder geocodeAddressString:@"Springfield, MA" completionHandler:^(NSArray* placemarks, NSError* error){
if (!error) {
for (CLPlacemark* aPlacemark in placemarks)
{
NSLog(@"place--%@", [aPlacemark locality]);
NSLog(@"lat--%f\nlong-- %f",aPlacemark.location.coordinate.latitude,aPlacemark.location.coordinate.longitude);
}
}
else{
NSLog(@"error--%@",[error localizedDescription]);
}
}];
}
【问题讨论】:
标签: ios objective-c geolocation core-location