-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NaN latitude and longitude #19
Comments
Hey Thomas thanks for bringing up this issue, |
Hey Yash, I am not using the library anymore, but in the past, I temporary "solved" the issue by resetting the Kalman filter when it was dirty. Here is some parts of the code: class LocationDataProvider: CLLocationManagerDelegate {
// ...
private var locationManager: CLLocationManager?
private var kalmanAlgorithm: HCKalmanAlgorithm?
// ...
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations.last!
var correctedLocation: CLLocation!
// Use the kalman algorithm to smooth location data
if self.kalmanAlgorithm == nil {
self.kalmanAlgorithm = HCKalmanAlgorithm(initialLocation: location)
correctedLocation = location
} else {
correctedLocation = self.kalmanAlgorithm!.processState(currentLocation: location)
}
correctedLocation = self.tempFixForNaNLocations(location: location, correctedLocation: correctedLocation)
// ... <Use correctedLocation>
}
// FIX: Temporary fix to avoid NaN locations: https://github.com/Hypercubesoft/HCKalmanFilter/issues/19
private func tempFixForNaNLocations(location: CLLocation, correctedLocation: CLLocation) -> CLLocation {
if correctedLocation.coordinate.latitude.isNaN || correctedLocation.coordinate.longitude.isNaN || correctedLocation.altitude.isNaN {
self.kalmanAlgorithm = HCKalmanAlgorithm(initialLocation: location)
return location
} else {
return correctedLocation
}
}
} Hope this can help you. |
Hey, Thomas Yeah, I too figured out a way something like that. |
We've had the same problem. It seems that the problem is the value of See lines 197, 198 and 199: After calculating the velocity, the outcome is:
What's the best approach? Should we skip the location? Or should the KalmanFilter be altered to devide by 1 instead of zero? |
Hey guys, I found this library right now and didn't test it yet but looked into this issue. For me it sounds as if you are using cached locations which you receive in your didUpdateLocations method because the timestamp of the new and previous location must be the same if these three values are 0. In my own app, I skip cached locations in my didUpdateLocations method when they are older than 10 seconds (however, you should test how many seconds fit to your case). I also skip locations which are invalid (horizontalAccuracy < 0) and those with an horizontalAccuracy over 30 meters.
This will not fix the library code which doesn't test for division by zero, but maybe this will help anyway. |
Hello, Just if some one else got this error. If they have the same timestamps some we do a division by 0 and we got a NaN. |
Hello,
I have an issue with the filter. Sometimes, the algorithm returns a location with both latitude and longitude NaN:
Usually, everything works fine and locations are smoothed correctly, but in certain circumstances the output location is NaN.
In case this can help you: the issue occurs indoor, the GPS signal is low, the phone is not moving on a table and the app fetches location in background every second. The problem starts sometimes after 3 minutes, sometimes after 1+ hour. Feel free to ask me if you need further information.
Thank you!
Thomas
The text was updated successfully, but these errors were encountered: