Created
December 9, 2015 23:01
-
-
Save osteele/4c400ab92bc15a49dfee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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