将 MKAnnotation 添加到 MKMapView 上方的位置,而不是在中心
Adding MKAnnotation to MKMapView above location, not in center
我在 MapView Coordinator class 中有这段代码,用于向地图添加注释:
func mapView(_ mapview: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
return mapview.dequeueReusableAnnotationView(withIdentifier: "myiconid")
}
在我的位置中心添加了注释:
如何在我的位置上方添加注释?
注释是根据您在制作时提供的经纬度设置的。我认为除非我们更改纬度和经度,否则我们无法将注释放在我们的位置上方。
文档说:
By default, the center point of an annotation view is placed at the coordinate point of the associated annotation. You can use this property to reposition the annotation view as needed. This x and y offset values are measured in points. Positive offset values move the annotation view down and to the right, while negative values move it up and to the left.
https://developer.apple.com/documentation/mapkit/mkannotationview/1452144-centeroffset
所以您可能想要更改注释的 centerOffset
属性...
我在 MapView Coordinator class 中有这段代码,用于向地图添加注释:
func mapView(_ mapview: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
return mapview.dequeueReusableAnnotationView(withIdentifier: "myiconid")
}
在我的位置中心添加了注释:
如何在我的位置上方添加注释?
注释是根据您在制作时提供的经纬度设置的。我认为除非我们更改纬度和经度,否则我们无法将注释放在我们的位置上方。
文档说:
By default, the center point of an annotation view is placed at the coordinate point of the associated annotation. You can use this property to reposition the annotation view as needed. This x and y offset values are measured in points. Positive offset values move the annotation view down and to the right, while negative values move it up and to the left.
https://developer.apple.com/documentation/mapkit/mkannotationview/1452144-centeroffset
所以您可能想要更改注释的 centerOffset
属性...