我有一个MKMap。当用户第一次登录应用程序时,它会要求使用位置服务。我的问题是,如果用户点击确定,地图不会更新,也不会转到他们的位置。如果用户离开视图并返回,则地图可以正常工作。我该如何解决这个问题。
我试过这个没有成功 -
-(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];
}
}
答案 0 :(得分:1)
如果您在用户获得获取位置的许可后立即执行此操作,则[self.schoolMap userLocation]
很可能尚未找到合适的位置。相反,您可以在用户授予权限时将地图设置为followUserLocation,因为这将保持地图查看用户所在的位置,或者打开将继续触发didUpdateUserLocation
委托方法的CLLocationManager,直到您获得准确的修复和然后告诉它停止。