我需要用普通的蓝点和另一个带有不同标记的点来显示我的位置

I need to show my location with the normal blue dot and another point with a different marker

我更改了 mapView 中标记的设计,但在这样做时我更改了我的位置标记,这不是我想要的。我只想更改麻省理工学院的标记,以及我的位置之一,只保留所有地图上出现的普通蓝色标记。

这里我留下了一些可能会失败的代码。

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 条件开始并检查它。如果是用户位置,您 return nil 获取默认标记。