I am building a location based app. Is there anyway to make the location I am getting through CLLocationManager more accurate?
I need to make sure the accuracy is within 50 meters.
Here is my code so far:
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)
}
}
}
For accuracy of the returned location you need to check the horizontalAccuracy
of the location, that will give you the radius of uncertainty for the location (in meters) you can then decide to act on or reject the location based on how accurate it is.