CLLocation 速度 return -1.0
CLLocation speed return -1.0
我有问题。我的 GPS(在 Wifi 中 iPad mini 2 和 3G/4G 中 iPhone 6)速度 return -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。
我有问题。我的 GPS(在 Wifi 中 iPad mini 2 和 3G/4G 中 iPhone 6)速度 return -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。