Ios 使用MapKit的跟踪模式
我有一个关于UserLocation e MapKit的问题 如果用户点击(或平移或捏捏)地图,我会跟随地图上的用户位置(如果用户位置发生变化,会自动移动地图),我会禁用“跟随模式”(如Apple map app) 我试过这个方法:Ios 使用MapKit的跟踪模式,ios,mapkit,Ios,Mapkit,我有一个关于UserLocation e MapKit的问题 如果用户点击(或平移或捏捏)地图,我会跟随地图上的用户位置(如果用户位置发生变化,会自动移动地图),我会禁用“跟随模式”(如Apple map app) 我试过这个方法: [_mapView setUserTrackingMode:MKUserTrackingModeFollowWithHeading animated:YES]; 这项工作很好,但我有一些问题: 是否可以在“跟随模式”期间设置特定的缩放级别 我注意到,如果他们处于
[_mapView setUserTrackingMode:MKUserTrackingModeFollowWithHeading animated:YES];
这项工作很好,但我有一些问题:
- 是否可以在“跟随模式”期间设置特定的缩放级别
- 我注意到,如果他们处于“跟随模式”,我捏了捏地图,“跟随模式”模式不会被中断。如果我仍然挤压贴图(或平移),则“跟随模式”会中断。我不明白你什么时候真的停止这种模式
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate, 200.0f, 200.0f);
[self.mapView setRegion:region animated:YES];
}
中心:
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {
[self.mapView setCenterCoordinate:userLocation.location.coordinate animated:YES];
}
来源:我想我知道你的意思,你可以试试,在
MKMapViewDelegate
:
func mapView(_mapView:MKMapView,didChangemode:MKUserTrackingMode,animated: Bool) {
mapView.setUserTrackingMode(.followWithHeading, animated: true)
}
当您滚动或缩放地图视图时,MKUserTrackingMode
将改变,
因此,您可以将其重置。我猜您希望将跟踪模式重置回自动跟随:
[_mapView setUserTrackingMode:MKUserTrackingModeFollowWithHeading animated:YES];
问题是什么时候重置。我建议
- 添加一个按钮(如Apple Maps中的导航箭头按钮),以便用户可以决定何时返回自动跟踪
- 或者制作一个计时器,在不活动时重置