ios - Apple MapKit:地图上的蓝点(用户位置)标记下未显示注释
问题描述
我正在使用 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
任何帮助将非常感激!
解决方案
推荐阅读
- php - 在 Laravel Eloquent get() 查询中插入未定义的变量
- ios - iOS Swift:UIImagePickerController HEIC 转 Jpg
- linq - 实体框架 LINQ 调用 switchoffset() 函数
- spring - 无法在 mac 的 Visual Studio 代码中创建 tomcat 服务器
- r - 等效于 ifelse 但在 R 中有一个选项?
- git - 如何检查git标签中是否存在文件夹
- azure-ad-b2c - 在使用 msal.js 的 Azure B2C 身份验证中,b2cScopes 的含义和语法是什么?
- networking - 有哪些方法可以确保 UDP 按顺序传送数据包?
- angular - 动态渲染组件
- tcp - 为什么 tcp 实现使用字节序列号而不是段号进行流量控制?