我改变了mapView中标记的设计,但是这样做我改变了我的位置标记,这不是我想要的。我只想更改MIT的标记,以及我的位置之一,只留下所有地图上显示的普通蓝色标记。
在这里,我留下一些可能失败的代码。
mapView.register(MKMarkerAnnotationView.self,
forAnnotationViewWithReuseIdentifier: MKMapViewDefaultClusterAnnotationViewReuseIdentifier)
let mitCoordinate = CLLocationCoordinate2D(latitude: -41.471373559102965, longitude: -72.94215917587279)
let mitAnnotation = SchoolAnnotation(coordinate: mitCoordinate, title: "MIT", subtitle: "mit - USA")
mapView.addAnnotation(mitAnnotation)
mapView.setRegion(mitAnnotation.region, animated: true)
extension BusinessViewController: MKMapViewDelegate {
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if let schoolAnnotationView
= mapView.dequeueReusableAnnotationView(withIdentifier: MKMapViewDefaultAnnotationViewReuseIdentifier) as? MKMarkerAnnotationView {
schoolAnnotationView
.animatesWhenAdded = true
schoolAnnotationView
.titleVisibility = .adaptive
schoolAnnotationView
.titleVisibility = .adaptive
return schoolAnnotationView
}
return nil
}
这是一张图片:
问题是你的实施
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
不会查看此annotation
是您的MIT注释还是您的用户位置注释。你需要从if
条件开始并检查。如果是用户位置,则返回nil
以获取默认标记。