在iOS 7中+;MKMapView调用mapView:didUpdateUserLocation:forever

在iOS 7中+;MKMapView调用mapView:didUpdateUserLocation:forever,ios,objective-c,mkmapview,mkmapviewdelegate,Ios,Objective C,Mkmapview,Mkmapviewdelegate,在myMapView中,点击按钮,我运行以下操作: - (IBAction)locate:(id)sender event:(UIEvent*)event { DLog(@""); if ([self.mapView respondsToSelector:@selector(userTrackingMode)]) { [self.mapView setUserTrackingMode:MKUserTrackingModeNone]; } [self

在my
MapView
中,点击按钮,我运行以下操作:

- (IBAction)locate:(id)sender event:(UIEvent*)event {
    DLog(@"");
    if ([self.mapView respondsToSelector:@selector(userTrackingMode)]) {
        [self.mapView setUserTrackingMode:MKUserTrackingModeNone];
    }
    [self.mapView setShowsUserLocation:NO];
    [self.mapView setShowsUserLocation:YES];
}
我看到
userLocation pin
,并调用以下方法更改地图位置:

- (void) resizeRegionToFitAllPins:(BOOL)includeUserLocation animated:(BOOL)animated {
    if ([self.annotations count] == 1) {
        NSObject<MKAnnotation> *annotation = [self.annotations objectAtIndex:0];
        BOOL isUserLocation = [annotation isKindOfClass:MKUserLocation.class];
        if ((includeUserLocation && isUserLocation) ||
            isUserLocation == NO) {
            CLLocationCoordinate2D coordinate;
            coordinate.latitude = annotation.coordinate.latitude;
            coordinate.longitude = annotation.coordinate.longitude;
            [self setRegion:MKCoordinateRegionMake(coordinate, MKCoordinateSpanMake(0.001f, 0.001f)) animated:animated];
        }
    }
}

是你说的
[self.mapView setshowerlocation:YES]。只要这种情况有效,地图视图将继续跟踪用户的位置。如果要停止跟踪,请告诉地图视图停止跟踪


但是,您可以使用地图视图的
userTrackingMode
(a
MKUserTrackingMode
值)更改跟踪行为。

您可以使用此方法避免反复调用方法
mapView:didUpdateUserLocation:

[self.locationManager stopUpdatingLocation];
在停止更新位置之前,请记住:

self.locationManager.delegate = self;
停止更新位置后,请记住:

self.locationManager.delegate = nil;

它的行为完全符合它的预期

当设备移动时,位置更新应该是连续的(但是如果它停止,并且精度低,更新的数量将变慢或停止)

然而,从字里行间看,这听起来并不是你的问题,因为你说:

"It is impossible to use the map after activating the user's location".
是的,这是可能的,事实上这对您来说是不可能的,这意味着问题的原因不是持续更新,而是您如何设计代码来处理这些持续更新。 不断更新地图是一种非常常见的情况

您需要执行以下操作:

  • 发布一个新问题,显示您的所有代码以及您想要的内容 确定如何正确设计程序以处理 持续更新

  • 添加代码以确保只调用
    ResizeRegionFitalPins
    无论何时添加或删除pin,或者如果位置发生更改,都会发生一次 一定距离。不是每次调用
    didUpdateLocation
    时 这就是造成你问题的原因

"It is impossible to use the map after activating the user's location".