地理编码器数组列表中的数据只显示mapview上的最后一个数据

时间:2017-02-05 01:56:08

标签: mkmapview mkreversegeocoder

我是编码新手,我遇到了这个问题。我尝试制作一个循环来对来自我的桌子的所有数据进行地理编码"餐馆"并在地图视图中显示它们,但是当我启动我的应用程序时,仅显示最后的数据。如何在地图上显示我的所有列表? 非常感谢您的帮助

让geoCoder = CLGeocoder()         var i = 0

    while i < restaurants.count-1 {
        i += 1
        geoCoder.geocodeAddressString(restaurants[i].location, completionHandler: {
            placemarks, error in
            if error != nil {
                print(error!)
                return
            }

            if let placemarks = placemarks {
                //Get the first placemarks
                let placemark = placemarks[0]

                //Add annotation
                let annotation = MKPointAnnotation()
                annotation.title = self.restaurants[i].name
                annotation.subtitle = self.restaurants[i].type



                if let location = placemark.location { annotation.coordinate = location.coordinate

                    self.mapView.showAnnotations([annotation], animated: true)
                    self.mapView.selectAnnotation(annotation, animated: true)


                    //set the zoom level
                    let region = MKCoordinateRegionMakeWithDistance(annotation.coordinate, 25000, 25000)
                    self.mapView.setRegion(region, animated: false)


                }

            }

        }
        )
    }

0 个答案:

没有答案