0

I am new in coding and i am blocked facing this issue. I try to make a loop to geocode all data from my table "restaurants" and show them on map view but when i launch my application only the last data is shown. How can i show all my list on the map ? Many thanks for your help

let 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)


                }

            }

        }
        )
    }
Joseph HK
  • 1
  • 2
  • I look on internet and it seems that my loop dont have a closure. I am a bit lost how to do the closure to show the location on the map at each loop – Joseph HK Feb 05 '17 at 04:15
  • for (_, restaurant) in restaurants.enumerated it works with that loop – Joseph HK Apr 23 '17 at 00:32

0 Answers0