Skip to content

Instantly share code, notes, and snippets.

@stansidel
Created March 4, 2016 08:07
Show Gist options
  • Save stansidel/d109da07f3428a669fd3 to your computer and use it in GitHub Desktop.
Save stansidel/d109da07f3428a669fd3 to your computer and use it in GitHub Desktop.
UCI9DC L78 Location Aware App
// MARK: - CLLocationManagerDelegate
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if let location = locations.first {
var text = "location: \(location.coordinate.latitude), \(location.coordinate.longitude)\n"
text += "course: \(location.course)\n"
text += "speed: \(location.speed)\n"
text += "altitude: \(location.altitude)\n"
CLGeocoder().reverseGeocodeLocation(location, completionHandler: { (placemarks, error) -> Void in
if error != nil {
print("Reverse geocoder failed with error: \(error!.localizedDescription)")
} else {
if let pm = placemarks?.first {
let address = "\(pm.locality ?? "") \(pm.postalCode ?? ""), \(pm.administrativeArea ?? ""), \(pm.country ?? "")"
text += "address: \(address)"
} else {
print("Problem with the data received from geocoder")
}
}
self.infoLabel.text = text
})
}
}
func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
print("Error while updating location " + error.localizedDescription)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment