Reputation: 348
I am implementing a Geolocation code, which means the I want to take an address as a string and then return a location in the form of a CLCoordinate. I get this strange error code that no one else is seeming to have seen.
kCLErrorDomain error 8
I don't have a map in this because I just want to be able to get a coordinate from an address string. Then use this coordinate later for another part of the program. I feel like I am missing something. Thanks for all your help!
@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;
}
The program does enter this method, but only to return this error: kCLErrorDomain error 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]);
}
}];
}
Upvotes: 0
Views: 803
Reputation: 348
Silly mistake, but just by restarting the iOS Simulator the problem was resolved.
Upvotes: 1
Reputation: 5047
Have you added to your info plist this key : NSLocationAlwaysUsageDescription
Upvotes: 0