【发布时间】:2017-01-05 20:18:30
【问题描述】:
我有一个列表,其中填充了来自 API 的数据。所以基本上流程是这样的:
当用户打开我的应用程序时:
if CLLocationManager.locationServicesEnabled() {
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.distanceFilter = 20
locationManager.startUpdatingLocation()
}
然后在我的func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) 中调用API 来获取数据。
但问题是 func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) 有时最多可以调用 5-6 次,因此会有很多 API 调用,如果我只获得一个位置,那么我获得一个可能很远的位置的机会很大远离用户。
关于如何解决这个问题的任何想法?我基本上想要最好的位置,并尽可能少地调用 API,这是最好的。
【问题讨论】:
-
只是几个想法:(a) 限制您自己的应用程序以每分钟最多发出 n 个请求; (b) 每个
CLLocation都有一个horizontalAccuracy属性。如果它太大,忽略位置 -
好评@CodeDifferent,关于
horizontalAccuracy的想法,位置管理器接受的最低准确度是多少?以便我知道我可以忽略什么。 -
您必须进行实验才能找到答案。 The National Library of Medicine 引用了一项研究,称 iPhone 3G 的准确度约为 8 米。那是在 2009 年。
标签: swift position locationmanager