首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在速度计应用程序中保持最大速度

在速度计应用程序中保持最大速度
EN

Stack Overflow用户
提问于 2016-02-29 14:40:23
回答 1查看 580关注 0票数 0

我正在做一个简单的速度计来学习斯威夫特和地理定位,我被困在最大速度。我想显示用户实现的最大速度,但我的标签显示当前速度。下面是函数的代码:

代码语言:javascript
运行
复制
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

我不知道为什么我的代码不起作用,我是不是遗漏了什么?

谢谢你的帮忙!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-02-29 14:44:56

您必须将最大速度从"func locationManager“中删除,因为在每次”迭代“(位置更改)时,最大速度被输入为0,因此最大速度总是小于速度。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35702344

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档