【问题标题】:Location monitoring not accurate while app running on the background应用程序在后台运行时位置监控不准确
【发布时间】:2016-03-07 00:26:03
【问题描述】:

我有一个 iOS 应用程序,它假设当某些事件发生时,无论应用程序是在前台还是后台,都会根据纬度和经度获取手机位置。
当应用程序在前台时,我总能得到准确的位置。
但是,当应用程序在后台运行时,有时我会获得准确的位置,有时会偏离一英里左右。当应用程序在后台运行时,我可以使用什么技巧来获得准确的位置?
这是我的部分代码。

var currentLocation = CLLocation()
var locManager = CLLocationManager()
.
.
locManager.desiredAccuracy = kCLLocationAccuracyBest;
.
.
currentLocation = locManager.location!
var long = String(currentLocation.coordinate.longitude)
var lat = String(currentLocation.coordinate.latitude)
var location = CLLocation(latitude:currentLocation.coordinate.latitude, longitude: currentLocation.coordinate.longitude)


还有没有办法知道我得到的位置是否准确?

【问题讨论】:

    标签: ios swift core-location


    【解决方案1】:

    尝试使用kCLLocationAccuracyBestForNavigation

    【讨论】:

    • kCLLocationAccuracyBestForNavigation 在一定程度上有所帮助。但我注意到的是,如果应用程序最近在后台运行,那么我会得到一个很好的位置。但是,如果应用程序在最后 30 分钟内处于后台,则位置不是很准确。我在想 GPS 启动可能需要一些时间,而应用程序正在尝试其他方式通过使用手机信号塔来获取位置?也有可能一旦事件发生,我等待 5 或 10 秒再尝试获取位置?这有帮助吗? – Borna 3 小时前
    • 我认为系统总是想节省电池电量,所以你可能需要计算一些位置信息,如果数据看起来正常,那么可能位置是准确的,否则你可以等待 5 或 10 秒.
    猜你喜欢
    • 2018-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-18
    相关资源
    最近更新 更多