Created
March 4, 2016 08:07
-
-
Save stansidel/d109da07f3428a669fd3 to your computer and use it in GitHub Desktop.
UCI9DC L78 Location Aware App
This file contains hidden or 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
// 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