Mapbox - setCenterCoordinate 正在取消选择注释
Mapbox - setCenterCoordinate is deselecting annotations
我正在试用 mapbox(使用 ios sdk),我 运行 遇到了一个问题,我认为我已经缩小了很多范围。这是我的代码:
func centerMap(location: CLLocationCoordinate2D) {
map.setCenterCoordinate(location,
zoomLevel: 14,
animated: true)
}
func mapView(mapView: MGLMapView, didDeselectAnnotation annotation: MGLAnnotation) {
dealDetails.hidden = false
}
func mapView(mapView: MGLMapView, didUpdateUserLocation userLocation: MGLUserLocation?) {
if let currentLocation = userLocation?.coordinate {
centerMap(currentLocation)
}
}
如果我在更新用户位置时没有重新居中地图(即,只是注释掉 centerMap(currentLocation)
调用),则注释将保持选中状态。将地图重新居中会调用 didDeselectAnnotation
函数,我不知道如何保持该注释处于选中状态。感谢您的帮助!
如果您更新中心坐标,我认为没有任何解决办法。您必须重新 select 注释。但是,您可能不需要这样做。如果您将地图视图上的 userTrackingMode
设置为 .Follow
,它应该会自动重新居中。
我正在试用 mapbox(使用 ios sdk),我 运行 遇到了一个问题,我认为我已经缩小了很多范围。这是我的代码:
func centerMap(location: CLLocationCoordinate2D) {
map.setCenterCoordinate(location,
zoomLevel: 14,
animated: true)
}
func mapView(mapView: MGLMapView, didDeselectAnnotation annotation: MGLAnnotation) {
dealDetails.hidden = false
}
func mapView(mapView: MGLMapView, didUpdateUserLocation userLocation: MGLUserLocation?) {
if let currentLocation = userLocation?.coordinate {
centerMap(currentLocation)
}
}
如果我在更新用户位置时没有重新居中地图(即,只是注释掉 centerMap(currentLocation)
调用),则注释将保持选中状态。将地图重新居中会调用 didDeselectAnnotation
函数,我不知道如何保持该注释处于选中状态。感谢您的帮助!
如果您更新中心坐标,我认为没有任何解决办法。您必须重新 select 注释。但是,您可能不需要这样做。如果您将地图视图上的 userTrackingMode
设置为 .Follow
,它应该会自动重新居中。