我正在使用一个MKUserTrackingBarButtonItem
按钮来允许用户自动跟踪他们在地图上的位置。问题是当他们点击这个按钮时,它被放大得太远了。我希望它以指定的缩放级别(即跨度)开始。我怎样才能做到这一点?
当用户点击按钮更改为 时MKUserTrackingModeFollow
,它似乎使用了与用户上次手动更改为相同的缩放级别(即使用地图上的手势)。尝试通过setRegion
或指定不同的缩放级别setVisibleMapRect
不会影响模式更改为 时将使用的缩放级别MKUserTrackingModeFollow
。
尝试override mapView:didChangeUserTrackingMode:
设置区域会导致模式更改回MKUserTrackingModeNone
。例子:
- (void)mapView:(MKMapView *)mapView didChangeUserTrackingMode:(MKUserTrackingMode)mode animated:(BOOL)animated {
if (mode == MKUserTrackingModeFollow) {
CLLocationCoordinate2D center = mapView.userLocation.location.coordinate;
MKCoordinateSpan span = MKCoordinateSpanMake(0.002306, 0.001717);
[mapView setRegion:MKCoordinateRegionMake(center, span) animated:YES];
// [mapView setUserTrackingMode:MKUserTrackingModeFollow animated:NO];
}
}
如果我在设置区域后立即尝试重置模式,如果用户静止,它会正常工作,但如果用户移动,它会缩小。
最简单的解决方案是,如果有一种方法可以通过发送我的跨度值来简单地为 MKUserTraking 指定缩放级别。但是,既然那似乎不存在,我还能做什么?