фильтр tableViewCells по позиции - PullRequest
0 голосов
/ 21 марта 2019

Я пытаюсь отфильтровать tableViewCells из фида по usersLocation автоматически от ближайшего к самому дальнему месту, где был создан пост ... сейчас я получаю usersPosition с помощью функции locationManager и превращаю координаты в метки, которые публикуются, но, в конце концов, они просто ярлыки, они не могут быть отсортированы по позиции ... Мой вопрос сейчас, если у вас есть идея, как я могу решить эту проблему, и я надеюсь, что вы поняли мой вопрос

locationManager:

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    if let lastLocation = locations.last {
        let geoCoder = CLGeocoder()

        //this is where you deal with the mapView to display current location
        let center = CLLocationCoordinate2D(latitude: lastLocation.coordinate.latitude, longitude: lastLocation.coordinate.longitude)
        let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))
        map.setRegion(region, animated: true)

        let annotation = MKPointAnnotation()
        annotation.coordinate = manager.location!.coordinate
        annotation.title = "Your current Location"
        annotation.subtitle = "No worries, your exact position won't be shared"
        map.addAnnotation(annotation)

        geoCoder.reverseGeocodeLocation(lastLocation) { (placeMarks, error) in
            if error == nil {
                if let firstLocation = placeMarks?[0] {
                    self.locationManager.stopUpdatingLocation()

                    if let cityName = firstLocation.locality,
                        let street = firstLocation.thoroughfare {

                        self.scanLocation = "\(street), \(cityName)"
                        print("This is the current city name", cityName)
                        print("this is the current street address", street)
                        self.takenLocation = self.scanLocation!
                        self.userLocation.text = self.takenLocation
                    }
                }
            }
        }
    }
}
...