- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在构建一个跟踪应用程序,我发现我应该过滤掉 GPS 原始数据,因此我使用了卡尔曼滤波器,它确实使跟踪结果变得平滑。因此,我正在微调两个参数,为了能够在 iPhone 上随时更改这些参数,我添加了两个文本字段 @IBOutlet weak var filterValueTextField: UITextField!
和@IBOutlet weak var horizontalAccuracyTextField: UITextField
!我想将它们连接到参数 hcKalmanFilter?.rValue = 40.0
和guard mostRecentLocation.horizontalAccuracy < 60 else { return }
。我确实尝试了各种方法,但出现错误:
在此尝试中,无法使用“(String?)”类型的参数列表调用“Double”类型的初始值设定项: guard mostRecentLocation.horizontalAccuracy < Double(horizontalAccuracyTextField.text) else { return }
这是函数:
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)
}
}
}
}
在 @maddy 建议后我尝试这样处理:
var filterValue:Double = 40.0
guard let filterAmount:String? = filterValueTextField.text! else {return}
filterValue = Double(filterAmount)!
hcKalmanFilter?.rValue = filterValue
但我仍然收到错误:无法使用类型为“(String?)”的参数列表调用类型“Double”的初始值设定项
最佳答案
因此,在所有最佳实践建议和更正之后,该功能是:
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let filterValue = Double(filterValueTextField.text!)!
hcKalmanFilter?.rValue = filterValue
let horizontalAccuracy = Double(horizontalAccuracyTextField.text!)!
let verticalAccuracy = Double( verticalAccuracyTextField.text!)!
// make sure to get last location
guard let mostRecentLocation = locations.last else { return }
//make sure that it's a valid gps signal ( vertical -1 = no gps triangulation )
guard mostRecentLocation.horizontalAccuracy > 0 else { return }
guard mostRecentLocation.verticalAccuracy > 0 else { return }
// check angainst fine tuning parameters, filtering out locations with errors greater than values
guard mostRecentLocation.horizontalAccuracy < horizontalAccuracy else { return }
guard mostRecentLocation.verticalAccuracy < verticalAccuracy else { return }
// passing the surviving locations to kalman filter for further filtering aiming for precision
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)
}
}
}
}
关于ios - 如何使mostRecentLocation.horizontalAccuracy和hcKalmanFilter?.rValue可通过文本字段编辑? swift ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52027516/
我是一名优秀的程序员,十分优秀!