Objective C でユーザーの場所を表示する際に問題があります。stackoverflow、aaaand でここで見つけることができるすべてを試しましたが、うまくいきませんでした。
だから私はそのコードを持っています:
-(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];
}
すべてがViewController.mにあります。より正確には、.hファイルで宣言されたmapViewにあります。
@property (strong, nonatomic) IBOutlet MKMapView *mapView;
誰にもアイデアはありますか?私が持っているエラーは次のとおりです。
Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first.
ありがとう :)