【发布时间】:2020-06-10 00:10:19
【问题描述】:
我是 swift 新手 .. 我已经实现了 Google maps sdk,我还想在用户开始移动或驾驶他/她的汽车时显示速度。
我正在使用 CLLocationSpeed 并将其存储在变量中。
现在,当用户单击开始按钮进行导航时,我正在获取速度值,但它不会随着用户移动而改变。 我想让它更有活力。
我已经附上了相同标签的代码和图像..
var locationManager: CLLocationManager
var speedlabel: UILabel = UILabel()
var timerspeed: Timer?
var speed: CLLocationSpeed = CLLocationSpeed()
@objc func runspeedcheck() {
speedlabel.text = "\(speed)kph"
}
func startnavigation {
timerspeed = Timer(timeInterval: 1.0, target: self, selector: #selector(runspeedcheck), userInfo: nil, repeats: true)
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
speed = locationManager.location!.speed
}
是让它更加动态的正确方法,还是有什么方法可以在用户移动时更改速度标签 任何帮助表示赞赏!
感谢和问候
【问题讨论】:
-
timerspeed的声明在哪里?
-
它在速度标签下面..
-
看看我的回答。
标签: swift xcode cllocationmanager gmsmapview