 
         UIDevice.current.isBatteryMonitoringEnabled = true
 
+        timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(timerEvent), userInfo: nil, repeats: true)
+
         locationManager = CLLocationManager()
         locationManager.delegate = self
-        locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters // kCLLocationAccuracyBest
+        locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation // kCLLocationAccuracyNearestTenMeters // kCLLocationAccuracyBest
+//        locationManager.distanceFilter = 1.0
+//        locationManager.headingFilter = 5
+        locationManager.allowsBackgroundLocationUpdates = true
         locationManager.requestAlwaysAuthorization()
         locationManager.startUpdatingLocation()
 
         return true
     }
-    
-    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
-        let location = locations.last! as CLLocation
+
+    func timerEvent() {
+        print("timer")
+        let viewController = window?.rootViewController as! ViewController
+        let interval : TimeInterval = Date().timeIntervalSince(lastUpdateTime)
+        let intervalSeconds = Int(interval)
+        viewController.mySetLabelText(text: String(intervalSeconds))
+    }
+
+    func updateLocation() {
+        let location = locationManager.location! as CLLocation
 
         let success = sendJson(urlString: cloudUrlString, data: [
             "deviceId": deviceUuid(),

    var locationManager: CLLocationManager!
    var cloudUrlString = "https://steptracker.tw1.ru/track.php"
    var lastUpdateTime : Date!
    
    func deviceUuid() -> String {
        return (UIDevice.current.identifierForVendor?.uuidString)!
    }
    
    func sendJson(urlString: String, data: Any) -> Bool {
        var jsonData : Data
        do {

            "deviceName": UIDevice.current.name,
            "deviceSystemName": UIDevice.current.systemName,
            "deviceSystemVersion": UIDevice.current.systemVersion
            ])

        if (success) {
            print(Date(), "success update")
            lastUpdateTime = Date.init()
        }
    }
    
    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        updateLocation()
    }

    func applicationWillResignActive(_ application: UIApplication) {
