我正在使用Mapkit创建一个应用程序,用户可以在该应用程序上在地图上放置一个点标记(MKPointAnnotation)。 问题是:在蓝点(用户位置指示符)附近时,似乎未绘制注释。
这是我的代码段。在此代码段中,每当拖动地图时,我只需将点标记放置在地图中心。 除非蓝点也位于地图中间,否则不会在地图上绘制点标记。
override func viewDidLoad() {
super.viewDidLoad()
mapView = MKMapView(frame:self.view.frame)
mapView.delegate = self
mapView.mapType = .standard
mapView.isZoomEnabled = true
mapView.isScrollEnabled = true
mapView.isRotateEnabled = true
mapView.showsUserLocation = true
mapView.userTrackingMode = .follow
mapView.isUserInteractionEnabled = true
mapView.mapType = MKMapType.satellite
view.addSubview(mapView)
}
func mapViewDidChangeVisibleRegion(_ mapView: MKMapView) {
updateLocationMarker(coordinate: mapView.centerCoordinate, showTitle: false)
}
func updateLocationMarker(coordinate: CLLocationCoordinate2D, showTitle: Bool) {
if self.pointMarker != nil {
mapView.removeAnnotation(pointMarker)
}
self.pointMarker = MKPointAnnotation()
self.pointMarker.coordinate = coordinate
self.pointMarker.title = stringFromCoordinate(coordinate: coordinate)
self.mapView.addAnnotation(pointMarker)
}
似乎“蓝点”是MKAnnotation的一种特殊类型。 我尝试设置视图的显示优先级,但是它们似乎没有任何作用:
let pointMarkerView = self.mapView.view(for: pointMarker)
pointMarkerView?.displayPriority = .required
let userLocationView = self.mapView.view(for: mapView.userLocation)
userLocationView?.displayPriority = .defaultLow
任何帮助将不胜感激!