【发布时间】:2015-08-20 20:21:54
【问题描述】:
我正在构建一个基于位置的应用程序。有没有办法让我通过 CLLocationManager 获得的位置更准确?
我需要确保精度在 50 米以内。
到目前为止,这是我的代码:
func startSignificantChangeUpdates(){
if (locationManager.respondsToSelector(Selector("requestWhenInUseAuthorization"))) {
locationManager.requestWhenInUseAuthorization()
}else {
locationManager.startUpdatingLocation()
}
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation
location = locationManager.location
}
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
if let newLocation = locations.last as? CLLocation {
//Lets not bother if the location is less than 500 meters
let oldLocation = location
location = newLocation
var distance = oldLocation?.distanceFromLocation(newLocation)
if distance > 500 {
NSNotificationCenter.defaultCenter().postNotificationName("location", object: self)
}
if distance > 50 {
NSNotificationCenter.defaultCenter().postNotificationName("imatlocation", object: self)
}
}
}
【问题讨论】:
-
尽管您要求的准确性很高,但您可能得不到。有时该位置距离很远,即使在要求最佳精度时也可能相距一英里。因此,请确保您获得的准确度 是 而不是您所要求的准确度 。仅仅因为您要求特定的准确性并不意味着您得到了它。
标签: ios swift geolocation cllocationmanager