CLLocation速度返回-1.0



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

长:12.5245,纬度:41.9456,速度:-1.0,-3.6公里:

这里的代码在 didupdatlocations ()
    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。

最新更新