我在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
}
这是一张图片:
答案 0 :(得分:1)
问题是您的实现
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
不会查看此annotation
是您的MIT注释还是您的用户位置注释。您需要从if
条件开始并进行检查。如果是用户位置,则返回nil
以获取默认标记。