gpt4 book ai didi

ios - 检查用户实际移动的时间

转载 作者:行者123 更新时间:2023-11-30 13:31:22 25 4
gpt4 key购买 nike

我正在使用 MapKit 和 CoreLocation 构建 iOS 应用程序。我可以通过调用获取用户的当前位置:

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.setupUI()

locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.mapView.delegate = self
self.locationManager.startUpdatingLocation()
self.mapView.showsUserLocation = true
geoCoder = CLGeocoder()
}

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location: CLLocation = locations.last!
// self.addressView.text = "\(location.coordinate.latitude) \(location.coordinate.longitude)"

geoCode(location)
if (zoomed == false) {
zoomToUserLocationAnimated(true)
zoomed = true
}
}

但是即使用户没有移动,这个函数也会被调用。我在 OSX 上使用 iOS 模拟器,并且模拟了一个位置,所以我很确定模拟器不会移动,但仍然调用此函数,我想知道是否有办法检查用户是否做了实际行动?

谢谢

最佳答案

您必须将之前的位置与当前位置进行比较。但请注意,位置永远不会绝对精确,因此您应该确保与一些错误进行比较。

例如location.distanceTo(prevLocation) > 3

另请参阅CLLocation.horizo​​ntalAccuracyCLLocation.verticalAccuracy

请注意,位置通常是根据 GPS 计算得出的,并且 GPS 卫星也会移动。

另一个选项是检查速度 location.speed > X,其中 X 是某个非零值(同样,检查零也不是很安全)。

关于ios - 检查用户实际移动的时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36548886/

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