First you need to call -[CLLocationManager requestWhenInUseAuthorization]or -[CLLocationManager requestAlwaysAuthorization]. Actually, I called this method in Didload and even added in info.plist, still getting this error.
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = @"MapView";
[MapView setMapType:MKMapTypeStandard];
[MapView setZoomEnabled:YES];
[MapView setScrollEnabled:YES];
[MapView setShowsUserLocation:YES];
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
region.center.latitude = 23.0804 ;
region.center.longitude = 72.5241;
region.span.longitudeDelta = 0.01f;
region.span.latitudeDelta = 0.01f;
[MapView setRegion:region animated:YES];
[MapView setDelegate:self];
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager requestAlwaysAuthorization];
[locationManager requestWhenInUseAuthorization];
[locationManager startUpdatingLocation];
Display *ann = [[Display alloc] init];
ann.title = @" Gujarat";
ann.subtitle = @"High Court";
ann.coordinate = region.center;
[MapView addAnnotation:ann];
}
-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:
(id <MKAnnotation>)annotation {
MKPinAnnotationView *pinView = nil;
if(annotation != MapView.userLocation)
{
static NSString *defaultPinID = @"com.invasivecode.pin";
pinView = (MKPinAnnotationView *)[MapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinView == nil ) pinView = [[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:defaultPinID];
pinView.pinColor = MKPinAnnotationColorRed;
pinView.canShowCallout = YES;
pinView.animatesDrop = YES;
pinView.draggable = YES;
}
else {
[MapView.userLocation setTitle:@"I am here"];
}
return pinView;
}
-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
if (status == kCLAuthorizationStatusAuthorizedWhenInUse)
{
[locationManager startUpdatingLocation];
}
else if (status == kCLAuthorizationStatusDenied)
{
}
else
NSLog(@"Wrong location status");
}
and in the Display class for annotation
<MKAnnotation> {
CLLocationCoordinate2D coordinate;
NSString *title;
NSString *subtitle;
}
@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;
the code here does not display an invitation to obtain permission from the user to access his location, and because of this, we do not get the location of the desired place. Please help me be on it from yesterday.

source
share