问题描述
我有问题.我的GPS(在Wifi上的iPad mini 2和3G/4G上的iPhone 6)上,速度返回-1.0.有一个主意吗?这是我在控制台日志中收到的:
I have problem. My GPS (on iPad mini 2 in Wifi and on iPhone 6 in 3G/4G) the speed return -1.0. Have an idea?This what i receive in console log:
长:12.5245,纬度:41.9456,速度:-1.0,kph:-3.6
Long: 12.5245, Lat: 41.9456, Speed:-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) ")
推荐答案
我也遇到了这个问题.负值表示无效速度.大多数情况下,这是当您在建筑物内时发生的,并且由于建筑物的缘故,您的位置经常移动很多.
I had this problem too. A negative value means an invalid speed.This is most of the time occured when you're inside a building and your location is moving a lot due to the building.
一个简单的解决方法是:
A simple fix would be:
if speed < 0 {
speed = 0
}
这将检查速度是否为负.如果是,它将重置为0.
This checks if the speed is negative. If it is, it'll reset it to 0.
这篇关于CLLocation速度返回-1.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!