按位置过滤tableViewCells

时间:2019-03-21 14:21:47

标签: ios swift location mapkit

我尝试通过usersLocation自动从提要中过滤出feed中的tableViewCells,从最接近帖子创建位置的最远... 现在,我通过locationManager函数获得了usersPosition,并将坐标转换为要发布的标签,但是由于它们只是最后的标签,因此无法按位置进行排序... 我现在的问题是,如果您可能有一个想法,我将如何解决这个问题,希望您理解我的问题

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
                    }
                }
            }
        }
    }
}

0 个答案:

没有答案
相关问题