Chevron freezes on location update

'm currently developing an app that has GPS navigation on it. The problem I’m having is that sometimes (too many times) the chevron representing the user position freezes on location update and after some time (too much time) it jumps to the correct position and the cycle repeats. Here is a link to a short video with the problem occurring if anyone wants to watch.

This is my code to update the chevron position:

if let placemarks = placemarks, !placemarks.isEmpty {
for p in placemarks {
let pm = p as CLPlacemark
guard pm.location != nil else {return}
self.userLocation = pm.location?.coordinate
self.matcher?.setMatcherLocation(TTMatcherLocation(coordinate: self.userLocation, withBearing: self.userHeading, withBearingValid: true, withEPE: 0, withSpeed: pm.location!.speed > 0 ? pm.location!.speed : 5.0, withDuration: pm.location!.timestamp.timeIntervalSince1970 > 0 ? pm.location!.timestamp.timeIntervalSince1970 : 1))
self.isUserInRoute()
}
}

Any help would be much appreciated. Thanks

Hi,

I’m trying to reproduce the issue, but so far without any success :frowning:
Can you share which version of the SDK you are using?

Regards,
Mateusz

Hello, I was using version 2.4.610 but updated to version 2.4.699 a few days ago and yet the problem still persists. Thanks

Hi.

I just created a bug for that and as soon as I’ll get any new info, I’ll post it here.

Regards,
Mateusz

Hi,
Could you please provide us with more information? Where do you get these placemarks from? Maybe you can share an example app where this issue occurs?

Maybe some of the placemarks are too far from the route and matcher returns the last point, if you can provide me with informations I mentioned earlier I could investigate on that.

Regards,
Michał

Hi,
I get the placemarks from the CLLocation Manager Delegate callback, like this:

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    CLGeocoder().reverseGeocodeLocation(manager.location!, completionHandler: { [unowned self] (placemarks, error) -> Void in
        
        if error != nil {
            print("Error: " + error!.localizedDescription)
            return
        }
        
        if let placemarks = placemarks, !placemarks.isEmpty {
            for p in placemarks {
                let pm = p as CLPlacemark
                if let location = pm.location {
                    self.userLocation = location.coordinate
                    self.matcher?.setMatcherLocation(TTMatcherLocation(coordinate: self.userLocation, withBearing: self.userHeading, withBearingValid: true, withEPE: 0, withSpeed: location.speed > 0 ? location.speed : 5.0, withDuration: location.timestamp.timeIntervalSince1970 > 0 ? location.timestamp.timeIntervalSince1970 : Date().timeIntervalSince1970))
                    self.isUserInRoute()
                }
            }
        }
    })
}

The placemarks being too far away from the route is unlikely since I was driving my car with my iPhone on top of the route itself which is the A28 freeway one of Portugal’s most important freeway, I was heading south and I never stopped. I checked and both google maps and apple maps work flawlessly so I know it’s not device related. Thanks

Hi @blanka,
Thank you very much for providing more information!

I created an example app in which I used your solution and the app freezes as you described. My investigation lead me to assume that it’s caused by the CLGecoder(maybe because of too many requests at once?). Please consider using location returned by CLLocationManager, like this:

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        guard let location = locations.first else { return }
        matcher.setMatcherLocation(TTMatcherLocation(coordinate: location.coordinate))
}

Of course you can provide more information to the TTMatcherLocation's constructor.

I hope it helped. Please let me know if you have any troubles.

Regards,
Michał

Hi @mlubgan,
you are absolutely right, the problem was indeed the CLGecoder. I followed your solution and went for a ride and it did not freeze once . Thanks for the help.

1 Like