为什么我的注释没有显示?

问题描述 投票:0回答:1
import UIKit
import MapKit
//import Firebase

//    alle UIViewController() functions
class ThirdViewController: UIViewController {

    @IBOutlet weak var mapView: MKMapView!
    let locationManager = CLLocationManager()

    override func viewDidLoad()
    {
        super.viewDidLoad()
        requestLocationAccess()

        //Regio instellen
        var newRegion:MKCoordinateRegion = MKCoordinateRegion()
        newRegion.center.latitude = -25.106303;
        newRegion.center.longitude = 133.587542;
        newRegion.span.latitudeDelta = 30;
        newRegion.span.longitudeDelta = 30;

        self.mapView.setRegion(newRegion, animated: true)
        self.mapView.delegate = self

        if let cityDetailsPath = Bundle.main.path(forResource: "Hostels", ofType: "plist"){
            if let cityDetails = NSArray(contentsOfFile: cityDetailsPath) as? [[String: String]] {
                for city in cityDetails
                {
                    guard let latStr = city["latitude"] else { continue }
                    guard let lonStr = city["longitude"] else { continue }
                    guard let titleStr = city["title"] else { continue }
                    guard let subtitleStr = city["subTitle"] else { continue }

                    if let lat = Double(latStr) {
                        if let lon = Double(lonStr) {
                            let title = titleStr
                            let subTitle = subtitleStr

                            let annotation = PinAnnotation(coordinate: CLLocationCoordinate2DMake(lat,lon), title: title, subtitle: subTitle)

                            self.mapView.addAnnotation(annotation)
                        }
                    }
                }
            }
        }
    }

    // Vraag locatie toestemming
    func requestLocationAccess()
    {
        let status = CLLocationManager.authorizationStatus()

        switch status
        {
        case .authorizedAlways, .authorizedWhenInUse:
            return

        case .denied, .restricted:
            print("location access denied")

        default:
            locationManager.requestWhenInUseAuthorization()
        }
    }

    func showLocations(location:PinAnnotation){

    }
}

//    alle UISearchBarDelegate functions
extension ThirdViewController: UISearchBarDelegate {

}

//    alle MKMapViewDelegate functions
extension ThirdViewController: MKMapViewDelegate {
    func createViewAnnotationForMap(mapView:MKMapView, annotation:MKAnnotation)->MKAnnotationView {
        _ = "PinAnnotation"
        if let annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: "PinAnnotation") {
            return annotationView
        }
        else
        {
            let returnedAnnotationView:MKPinAnnotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier:"PinAnnotation")
            returnedAnnotationView.animatesDrop = true
            returnedAnnotationView.canShowCallout = true
            return returnedAnnotationView

        }

    }
}
ios annotations mkmapview mkannotation
1个回答
0
投票
let returnedAnnotationView:MKPinAnnotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier:"PinAnnotation")
returnedAnnotationView.animatesDrop = true
returnedAnnotationView.canShowCallout = true
return returnedAnnotationView
© www.soinside.com 2019 - 2024. All rights reserved.