0
我正在做一个简单的速度计来学习Swift和地理定位,并且我坚持最大速度。我想显示用户获得的最大速度,但是我的标签显示当前的速度。下面是函数的代码:保持速度计应用程序的最大速度
func locationManager(manager:CLLocationManager, didUpdateLocations locations:[CLLocation]) {
var latestLocation = locations.last as CLLocation!
var maxSpeed: Double = 0
latLabel.text = "\(latestLocation.coordinate.latitude)"
lonLabel.text = "\(latestLocation.coordinate.longitude)"
var speed: CLLocationSpeed = CLLocationSpeed()
speed = locationManager.location!.speed
if(speed<0){
speed=0;
}
speedLabel.text = String(format: "%.0f km/h", speed * 3.6)
maxSpeed = max(maxSpeed, speed)
maxSpeedLabel.text = String(format: "%.0f km/h", maxSpeed*3.6)
}
我想的是,speedLabel显示当前速度,以及maxSpeedLabel改变仅在当前速度较高。如果我不清楚,这里是什么是它现在做:
(速度 - 最高速度)
3 - 3
4 - 4
5 - 5
4 - 4
这里是我想达到的目标:
(速度 - 最高速度)
3 - 3
4 - 4
5 - 5
4 - 5
6 - 6
3 - 6
我不知道为什么我的代码不工作,我错过了什么?
感谢您的帮助!
这是小这么简单...非常感谢,我会尽快接受你的回答! (从现在开始〜7分钟) – nommis
没问题,祝你有个美好的一天! –
谢谢,你也是! – nommis