我有一个 MKMap。当用户首次登录应用程序时,它会要求使用定位服务。我的问题是,如果用户单击确定, map 不会更新,也不会到达他们的位置。如果用户离开 View 并返回,则 map 有效。我该如何解决这个问题。
我试过了,没有成功-
-(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];
}
}
最佳答案
如果您在用户授予获取位置的权限后立即执行此操作,则 [self.schoolMap userLocation]
很可能还没有找到合适的位置。相反,您可以在用户授予权限时将 map 设置为 followUserLocation,因为这将使 map 始终查看用户所在的位置,或者打开 CLLocationManager 将继续触发 didUpdateUserLocation
委托(delegate)方法,直到您获得准确修复,然后告诉它停止。
关于ios - 授予使用位置服务的权限后 map 未更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21652474/