 
 let CLOUD_URL: String = "https://steptracker.tw1.ru/track.php"
 let LOCATIONS_QUEUE_LIMIT: Int = 99
-let LOCATION_UPDATE_INTERVAL: Double = 180
+let LOCATION_UPDATE_INTERVAL: Double = 20
+let MIN_GPS_ACCURACY: Double = 300;
 
 @UIApplicationMain
 class AppDelegate: UIResponder, UIApplicationDelegate, CLLocationManagerDelegate {

        lastSendTime = Date.init(timeIntervalSince1970: 0)
        lastLocationTime = Date.init(timeIntervalSince1970: 0)
        previousLocationTime = Date.init(timeIntervalSince1970: 0)

        if (!CLLocationManager.locationServicesEnabled()) {
            print("No location manager. Exit")

        sendLocationsToCloud()
    }

    func updateLocation() -> Bool {
        let location = locationManager.location! as CLLocation
        let horizontalAccuracy = location.horizontalAccuracy

        print("try updateLocation with horizontalAccuracy:", horizontalAccuracy)
        if (horizontalAccuracy > MIN_GPS_ACCURACY) {
            print("----not updateLocation. Min accuracy")
            return false
        }

        let newLocationTime = Date()
        print("timediff", newLocationTime.timeIntervalSince(previousLocationTime))
        if (newLocationTime.timeIntervalSince(previousLocationTime) < 5) {
            if (Double(horizontalAccuracy) < Double(previousHorizontalAccuracy)) {
                print("----too frequently, but accuracy better. Continue")
            } else {
                print("----not updateLocation. Too frequently")
                return false
            }
        }

        let jsonData = try! JSONSerialization.data(withJSONObject: [
            "deviceId": deviceUuid(),
            "latitude": location.coordinate.latitude,
            "longitude": location.coordinate.longitude,
            "horizontalAccuracy": horizontalAccuracy,
            "verticalAccuracy": location.verticalAccuracy,
            "timestamp": newLocationTime.timeIntervalSince1970,
            "speed": location.speed,
