Обновление метки времени при изменении местоположения пользователя - PullRequest
0 голосов
/ 20 февраля 2019

У меня здесь есть приложение, я получаю местоположение пользователя и получаю метку времени.проблема, с которой я столкнулся сейчас, заключается в том, что временная метка продолжает обновляться, но я хочу, чтобы она обновлялась только при изменении координаты местоположения.

public func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

        getLocation(location: locations.last?.coordinate)
}



func getLocation(location manager: CLLocationCoordinate2D) {

            let loc = CLLocation(latitude: manager.latitude, longitude: manager.longitude)
            let geoTag = GeoTag()
            let coordinates = Coordinate()
            coordinates.accuracy = Double(loc.horizontalAccuracy).rounded(toPlaces: 3)
            coordinates.altitude = Double(loc.altitude).rounded(toPlaces: 7)
            coordinates.heading = 0.0
            coordinates.lat = Double(loc.coordinate.latitude).rounded(toPlaces: 7)
            coordinates.lng = Double(loc.coordinate.longitude).rounded(toPlaces: 7)
            coordinates.speed = loc.speed

            geoTag.coordinates = coordinates
            geoTag.timestamp = "\(Double(loc.timestamp.timeIntervalSince1970).rounded(toPlaces: 0) * 1000))"

    }

больше кода будет предоставлено по запросу

1 Ответ

0 голосов
/ 20 февраля 2019

Хорошо, когда вы устанавливаете свой делегат для locationManager, вы также должны добавить следующую строку

    locationManager.startMonitoringSignificantLocationChanges() //this will call //didUpdateLocations after a significant change in location

или

locationManager.distanceFilter = 20  // replace it with what distance in meters you want //this will call you didUpdateLocations method after you travel 20 meters
...