I am new to Swift. I had implemented Google maps sdk also I want to display the speed when the user starts moving or driving his/her car.
I am using CLLocationSpeed and storing it in a variable.
Right now I am getting the speed value when user clicks start button for navigation but its not changing as the user moves. I want to make it more dynamic.
I have attached the code and image for the label for the same:
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
}
Is it right way to make it more dynamic, or is there any way to make changes in the speed label as the user moves?