Skip to content

Instantly share code, notes, and snippets.

@osteele
Created December 9, 2015 23:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save osteele/4c400ab92bc15a49dfee to your computer and use it in GitHub Desktop.
Save osteele/4c400ab92bc15a49dfee to your computer and use it in GitHub Desktop.
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [AnyObject]) {
let location = locations.lastObject as! CLLocation
if let lastLocation = lastGeocodedLocation {
if lastLocation.distanceFromLocation(location) < distanceFilter {
NSLog("current location is within \(round(distanceFilter))m of previous location")
return
}
if abs(location.coordinate.latitude - lastLocation.coordinate.latitude) < lastLocation.horizontalAccuracy &&
abs(location.coordinate.longitude - lastLocation.coordinate.longitude) < lastLocation.verticalAccuracy {
var distance = sqrt(pow(lastLocation.horizontalAccuracy,2) + pow(lastLocation.verticalAccuracy,2))
NSLog("current location is within accuracy=\(round(distance))m of previous location")
return
}
}
// TODO throttle frequency
lastGeocodedLocation = location
locationManager.allowDeferredLocationUpdatesUntilTraveled(10, timeout:15*60)
geocoder.reverseGeocodeLocation(location) {(placemarks, error) in
if error != nil {
NSLog("%@", error)
return
}
let place = placemarks.first as CLPlacemark
self.delegate?.locationManager?(self, didUpdatePlacemark: place, location: location)
self.locationUploader?.locationManager?(self, didUpdatePlacemark: place, location: location)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment