在我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];
}
}
}
我的问题是地图正在永远更新用户的位置(循环中)。激活用户位置后无法使用地图。有什么必要让它停止更新用户的位置并允许用户使用地图?
该方法mapView:didUpdateUserLocation:
被一遍又一遍地调用。我把 放在MKMapViewDelegate
界面上,设置self.mapView.delegate
为 self 并设置mapViewWillStartLocatingUser:
andmapViewDidStopLocatingUser:
只用一个Dlog(@"")
电话;mapViewDidStopLocatingUser:
永远不会被调用。
- (void)mapView:(MKMapView *)map didUpdateUserLocation:(MKUserLocation *)userLocation {
DLog(@"Resizing...");
[self.mapView resizeRegionToFitAllPins:YES animated:YES];
}
}
- (void)mapViewWillStartLocatingUser:(MKMapView *)mapView {
DLog(@"");
}
- (void)mapViewDidStopLocatingUser:(MKMapView *)mapView {
DLog(@"");
}