为什么在地图上只显示一个注释?

时间:2018-08-19 10:00:30

标签: ios swift maps

我试图在地图上显示多个位置,但最后只显示地图上的最后一个点。

能帮我吗?

谢谢

var annotationArray  : [MKPointAnnotation] = []

override func viewDidLoad() {
    super.viewDidLoad()
    let distanceSpan :CLLocationDegrees = 2000
    haritaView?.showsUserLocation = true

    let points = [
            ["title": "New York, NY",    "latitude": 41.044185, "longitude": 29.00734829999999],
            ["title": "Los Angeles, CA", "latitude": 41.031493, "longitude": 28.982564300000035],
            ["title": "Chicago, IL",     "latitude": 41.0511273, "longitude": 28.992835199999945]
    ]

    for point in points {
        let annotation = MKPointAnnotation()
        annotation.title = point["title"] as? String
        annotation.coordinate = CLLocationCoordinate2D(latitude: point["latitude"] as! Double, longitude: point["longitude"] as! Double)
        self.annotationArray.append(annotation)
    }

    print(self.annotationArray.count)
    dump(self.annotationArray)

    haritaView.addAnnotations(annotationArray)

    for point in self.annotationArray {
        self.haritaView.addAnnotation(point as MKAnnotation)
    }
}

0 个答案:

没有答案