我需要用正常的蓝点显示我的位置,用另一个标记显示另一个点

问题描述 投票:1回答:1

我改变了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
    }

这是一张图片:

swift mapkit
1个回答
1
投票

问题是你的实施

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {

不会查看此annotation是您的MIT注释还是您的用户位置注释。你需要从if条件开始并检查。如果是用户位置,则返回nil以获取默认标记。

© www.soinside.com 2019 - 2024. All rights reserved.