I have an issue showing user locations in objective C. I tried everything i could find here in stackoverflow, aaaand, didn't work.
So I have that code :
-(void)setLocation
{
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
MKPointAnnotation *myAnnotation = [[MKPointAnnotation alloc]init];
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
locationManager.distanceFilter = 10.0;
[locationManager startUpdatingLocation];
[locationManager requestWhenInUseAuthorization];
[locationManager requestAlwaysAuthorization];
myAnnotation.coordinate = mapView.userLocation.location.coordinate;
myAnnotation.title = @"Test";
myAnnotation.subtitle = @"I am a test Subtitle";
[self.mapView addAnnotation:myAnnotation];
}
-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {
[self.mapView setCenterCoordinate:userLocation.coordinate animated:YES];
}
Everything is in ViewController.m, more precisely in a mapView declared in my .h file:
@property (strong, nonatomic) IBOutlet MKMapView *mapView;
Does anyone have any idea ? The error i have is that:
Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first.
Thanks :)