自定义用户位置注释标注不起作用

时间:2016-05-28 12:10:49

标签: swift mapkit

我想在Swift中更改用户位置注释的标准注释标注视图。

因此我创建了一个自定义XIB和一个自定义类。在mapkit委托中,我加载了相应的注释。每个地图注释都会按预期添加自定义注释,但不会显示“当前用户位置”。这里标准的仍在显示。我如何更改我的代码,以便将标准代码交换到下面的代码?

enter image description here

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

        var identifier = ""

        if (annotation is MKUserLocation) {
            identifier = "userLocation"
            let annotationInfo:[String:AnyObject] = ["featureTypeId": GISFeatureType.AnnotationCurrentPosition.rawValue]

            if let userAnnotation = MapAnnotation(annotationInfo: annotationInfo) {
                userAnnotation.title = "Aktueller Standort"
                let annotationView = MapAnnotationView(annotation: userAnnotation, reuseIdentifier: identifier)
                annotationView.canShowCallout = true

                return annotationView
            }
        }

        // Annotation is not user location
        guard let annotation = annotation as? MapAnnotation, let featureTypeId = annotation.featureTypeId else {
            return nil
        }

        identifier = "MapAnnotation"
        let annotationView = MapAnnotationView(annotation: annotation, reuseIdentifier: identifier)

        switch (featureTypeId) {
        case .AnnotationIncident:
            identifier = "MapAnnotationIncidentDetailView"
            let detailView = UIView.loadFromNibNamed(identifier) as! MapAnnotationIncidentDetailView
            detailView.incident = annotation.incident
            annotationView.detailCalloutAccessoryView = detailView

        case .AnnotationAED:
            identifier = "MapAnnotationAEDDetailView"
            let detailView = UIView.loadFromNibNamed(identifier) as! MapAnnotationAEDDetailView
            detailView.aed = annotation.aed
            annotationView.detailCalloutAccessoryView = detailView

        case .AnnotationCurrentPosition:
            identifier = "MapAnnotationCurrentDetailView"
            let detailView = UIView.loadFromNibNamed(identifier) as! MapAnnotationCurrentDetailView
            annotationView.detailCalloutAccessoryView = detailView

        default:
            return nil
        }


        annotationView.canShowCallout = true
        return annotationView
    }

0 个答案:

没有答案