【发布时间】:2015-05-27 16:42:31
【问题描述】:
在我的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: 和mapViewDidStopLocatingUser:,只调用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(@"");
}
【问题讨论】:
标签: ios objective-c mkmapview mkmapviewdelegate