I'm building a tracking app and I found out that I should filter out GPS raw data, so I'm using a Kalman filter, and it really smooths out the resulting tracking. So I'm fine tuning two parameters, and in order to be able to change those parameters on the go from the iPhone I added two textfields @IBOutlet weak var filterValueTextField: UITextField!
and @IBOutlet weak var horizontalAccuracyTextField: UITextField
! and I want to connected those to the parameters hcKalmanFilter?.rValue = 40.0
and guard mostRecentLocation.horizontalAccuracy < 60 else { return }
. I did try various ways but I get an error:
Cannot invoke initializer for type 'Double' with an argument list of type '(String?)' on this try:
guard mostRecentLocation.horizontalAccuracy < Double(horizontalAccuracyTextField.text) else { return }
This is the function:
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
hcKalmanFilter?.rValue = 40.0
guard let mostRecentLocation = locations.last else { return }
guard mostRecentLocation.horizontalAccuracy > 0 else { return }
guard mostRecentLocation.horizontalAccuracy < 60 else { return }
guard mostRecentLocation.horizontalAccuracy < horizontalAccuracy else { return }
var myLocation: CLLocation = mostRecentLocation
if hcKalmanFilter == nil {
self.hcKalmanFilter = HCKalmanAlgorithm(initialLocation: myLocation)
}
else {
if let hcKalmanFilter = self.hcKalmanFilter {
if resetKalmanFilter == true {
hcKalmanFilter.resetKalman(newStartLocation: myLocation)
resetKalmanFilter = false
}
else {
let kalmanLocation = hcKalmanFilter.processState(currentLocation: myLocation)
self.actualRouteInUseCoordinatesArray.append(kalmanLocation.coordinate)
}
}
}
}
I tried to handle it like this after @maddy advises :
var filterValue:Double = 40.0
guard let filterAmount:String? = filterValueTextField.text! else {return}
filterValue = Double(filterAmount)!
hcKalmanFilter?.rValue = filterValue
but I still get error : Cannot invoke initializer for type 'Double' with an argument list of type '(String?)'