I've problem with getting my current location. I still getting error:
Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed. (kCLErrorDomain error 0.)"
I already did everything that I found here:
Reset content and settings in iOS Simulator (map application in simulator shows correct location).
In Xcode at Product>Scheme>Edit I unmarked Allow Location Simulation (when I mark it,It simulate e.g. London).
I have added NSLocationWhenInUseUsageDescription to Info.plist file in my project (App asks for Location permissions and I can see them in Settings in iOS simulator).
I have Wi-Fi connection turned on (like I said location services works fine in Safari, Maps or even Maps in iOS Simulator).
-(void)viewDidLoad {
[super viewDidLoad];
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
if(IS_OS_8_OR_LATER){
NSUInteger code = [CLLocationManager authorizationStatus];
if (code == kCLAuthorizationStatusNotDetermined && ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])) {
if([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"]) {
[self.locationManager requestWhenInUseAuthorization];
} else {
NSLog(@"Info.plist does not contain NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription");
}
}
}
[self.locationManager startUpdatingLocation];
[self.FirstMap setShowsUserLocation:YES]; }
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
NSLog(@"didFailWithError: %@", error);
UIAlertView *errorAlert = [[UIAlertView alloc]
initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[errorAlert show]; }
Is there something that i forgot about? Thanks!
I guess maybe you need to read this thread first as it's largely overlapped.
Location Manager Error : (KCLErrorDomain error 0)
But anyway, I tested your code and got the same error as you reported. Then I change the simulation configuration. To be specific, in the simulator, I clicked Debug -> Location -> Custom Location... and enter a coordinate, and I can periodically receive location events (at a speed of every sample per second.) So maybe the problem is not from the code but from the simulator itself. Hope my answer helps.
UPDATE
I guess I misunderstood your question. What you want is to "automatically" get your current location in simulator. I'm afraid there's no such feature in xcode, instead, you need to use "add gpx file to project", which is even more work than using customized location. But I mean, if you've successfully got correct locations, why it bothers you to get the correct current location from the simulator, or alternative, maybe you can test on phone?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With