2014-11-06 56 views
0

我正在实现一个地理定位代码,这意味着我想要一个地址作为一个字符串,然后返回一个位置的形式的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]); 
    } 
}]; 

} 

回答

0

已添加到您的信息的plist此项:NSLocationAlwaysUsageDescription

1

愚蠢的错误,但只是通过重新启动iOS模拟器的问题是r esolved。