我正在做一个简单的速度计来学习斯威夫特和地理定位,我被困在最大速度。我想显示用户实现的最大速度,但我的标签显示当前速度。下面是函数的代码:
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
我不知道为什么我的代码不起作用,我是不是遗漏了什么?
谢谢你的帮忙!
发布于 2016-02-29 14:44:56
您必须将最大速度从"func locationManager“中删除,因为在每次”迭代“(位置更改)时,最大速度被输入为0,因此最大速度总是小于速度。
https://stackoverflow.com/questions/35702344
复制相似问题