我正在實現一個地理定位代碼,這意味着我想要一個地址作爲一個字符串,然後返回一個位置的形式的CLCoordinate。我得到了這個奇怪的錯誤代碼,沒有其他人似乎看到過。GeoLocation找到一個座標變得kCLErrorDomain錯誤8
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]);
}
}];
}