gpt4 book ai didi

ios - CLLocation速度返回-1.0

转载 作者:行者123 更新时间:2023-11-28 12:42:10 35 4
gpt4 key购买 nike

我有问题。我的 GPS(在 Wifi 的 iPad mini 2 和 3G/4G 的 iPhone 6 上)速度返回 -1.0。有想法吗?这是我在控制台日志中收到的内容:

经度:12.5245,纬度:41.9456,速度:-1.0,kph:-3.6

这里是 didUpdateLocations() 中的代码

    let userLocation: CLLocation = locations[0]
var speed: CLLocationSpeed = CLLocationSpeed()
speed = (locationManager.location?.speed)!

SpeedLabel.text = String(format: "%.0f km/h", speed * 3.6)
let long = String(Float(userLocation.coordinate.longitude))
let lat = String(Float(userLocation.coordinate.latitude))


print("Long: \(long), Lat: \(lat), Speed:\(speed), kph: \(speed * 3.6) ")

最佳答案

我也遇到过这个问题。负值表示无效速度。大多数情况下,当您在建筑物内并且您的位置因建筑物而移动很多时会发生这种情况。

一个简单的解决方法是:

if speed < 0 { 
speed = 0
}

这会检查速度是否为负数。如果是,它将重置为 0。

关于ios - CLLocation速度返回-1.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39172130/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com