0

Hi every one Here is my issue

I'm trying to set a timer so it let the user walk a bit before present a message in the future. I've look in most documented website but it won't work.

In console I get print timestamp every seconds

                   ------------------------------


extension TrackHistoryTableViewController: CLLocationManagerDelegate {

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    let seconds = 300.0
    
    if previousLocation == nil { previousLocation = locations.first
    } else {
        guard let newLocation = locations.last else { return }
        
        if newLocation.speed > 0  {
            DispatchQueue.main.asyncAfter(deadline: .now() + seconds) {
                print("Too slow")
                print(newLocation.timestamp)
            }
            if newLocation.speed < 1  {
         
                DispatchQueue.main.asyncAfter(deadline: .now() + seconds) {
                    print("Too slow")
                    print(newLocation.timestamp)
                }
                
            } else if newLocation.speed >= 8.8  {
                
                DispatchQueue.main.asyncAfter(deadline: .now() + seconds) {
                    print("too fast")
                    print(newLocation.timestamp)

                }
                print("too fast")
                print(newLocation.timestamp)

            }
        } else {
            locationManager?.startUpdatingLocation()
        }
Giovanni Gaffé
  • 36
  • 1
  • 1
  • 10
  • What are you trying to achieve? You wanna let user walk for 300 seconds and check if the user has walked fast, slow, too fast or too slow? Is that it? – Sandeep Bhandari Feb 18 '21 at 05:14
  • If user use app more and let it run to gain some walk during the day I want to present alert if he stop. When I tried it get block because it can't in one second be in a normal pace. – Giovanni Gaffé Feb 18 '21 at 05:19
  • I dont think you understand how core location works, you cant get location update at a regular interval using `didUpdateLocations`, this delegate gets called when user actually moves, it obviously depends on the accuracy filter you have set to location manager as well. So your idea of getting location update and checking time stamp of it might not yield user location at exact 300th second, imagine someone opens the app and doesnt move for 300 sec, `didUpdateLocations` will not be triggered so u wont get user speed, also you shouldnt be calling `startUpdatingLocation` in `didUpdateLocations` – Sandeep Bhandari Feb 18 '21 at 05:24
  • I wrote this to answer a similar question in the past read: https://stackoverflow.com/questions/43182835/best-way-to-use-background-location-updates-in-ios-swift/43183274#43183274 – Sandeep Bhandari Feb 18 '21 at 05:25
  • Thanks @SandeepBhandari I will look forward to get a better understanding – Giovanni Gaffé Feb 18 '21 at 05:26

0 Answers0