【发布时间】:2014-04-21 07:31:34
【问题描述】:
我正在使用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 指定缩放级别。但是,既然这似乎不存在,我还能做什么?
【问题讨论】:
-
您找到解决方案了吗?我目前正在努力解决同样的问题。
标签: ios objective-c mapkit apple-maps