0
我有一個MKMap。當用戶第一次登錄到應用程序時,它會要求使用位置服務。我的問題是,如果用戶點擊確定,地圖不會更新,並且不會到達他們的位置。如果用戶離開視圖並返回,則地圖起作用。我將如何解決這個問題。如果你一旦用戶授予權限,以獲得它很可能是[self.schoolMap userLocation]
還沒有得到一個很好的位置,但位置做這個使用位置服務的許可後地圖不更新
-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
if (status == kCLAuthorizationStatusDenied) {
AMBlurView *mapBlurred = [AMBlurView new];
mapBlurred.frame = self.view.bounds;
[self.view addSubview:mapBlurred];
MKCoordinateSpan span = MKCoordinateSpanMake(52.0f,80.0001f);
CLLocationCoordinate2D coordinate = {37.7833, 122.4167};
MKCoordinateRegion region = {coordinate, span};
MKCoordinateRegion regionThatFits = [self.schoolMap regionThatFits:region];
NSLog(@"Fit Region %f %f", regionThatFits.center.latitude, regionThatFits.center.longitude);
[self.schoolMap setRegion:regionThatFits animated:YES];
[self.view bringSubviewToFront:self.schoolTextBlur];
[self.view bringSubviewToFront:self.autocompleteTableView];
[self.view bringSubviewToFront:self.schoolText];
[self.view bringSubviewToFront:self.theLine];
[self.view bringSubviewToFront:self.theLine2];
[self showLocationUnavailable];
}
else if (status == kCLAuthorizationStatusAuthorized) {
MKUserLocation *myLocation = [self.schoolMap userLocation];
CLLocationCoordinate2D coord = [[myLocation location] coordinate];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(coord, 9000, 9000);
[self.schoolMap setRegion:region animated:YES];
}
}
除了CLLocationManager委託方法,[MKMapViewDelegate](https://developer.apple.com/library/ios/documentation/MapKit/Reference/MKMapViewDelegate_Protocol/MKMapViewDelegate/MKMapViewDelegate.html#//apple_ref/occ/ intf/MKMapViewDelegate)協議包括幾種用於響應用戶位置更新的方法,例如'mapViewWillStartLocatingUser:'和'mapView:didUpdateUserLocation:'。 –