2014-02-08 25 views
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]; 

    } 
} 

回答

1

-

我都没有成功尝试这样做。相反,您可以在用户授予权限时将地图设置为FollowUserLocation,因为这样可以保持地图查看用户所在的位置,或者启用CLLocationManager,它将继续触发代理方法,直到获得准确的修复,然后将其告知停止。

+0

除了CLLocationManager委托方法,[MKMapViewDelegate](https://developer.apple.com/library/ios/documentation/MapKit/Reference/MKMapViewDelegate_Protocol/MKMapViewDelegate/MKMapViewDelegate.html#//apple_ref/occ/ intf/MKMapViewDelegate)协议包括几种用于响应用户位置更新的方法,例如'mapViewWillStartLocatingUser:'和'mapView:didUpdateUserLocation:'。 –

相关问题