Guest User

Untitled

a guest
Jan 19th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. import UIKit
  2. import CoreLocation
  3.  
  4. class ViewController: UIViewController, CLLocationManagerDelegate{
  5. @IBOutlet weak var lat: UILabel!
  6. @IBOutlet weak var long: UILabel!
  7. @IBOutlet weak var course: UILabel!
  8.  
  9. @IBOutlet weak var speed: UILabel!
  10.  
  11. @IBOutlet weak var altitude: UILabel!
  12. @IBOutlet weak var add: UILabel!
  13. var manager = CLLocationManager()
  14. override func viewDidLoad() {
  15. super.viewDidLoad()
  16. // Do any additional setup after loading the view, typically from a nib.
  17. manager.delegate = self
  18. manager.desiredAccuracy = kCLLocationAccuracyBest
  19. manager.requestWhenInUseAuthorization()
  20. manager.startUpdatingLocation()
  21. }
  22. func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
  23. let location = locations[0]
  24. self.lat.text = String(location.coordinate.latitude)
  25. self.long.text = String(location.coordinate.longitude)
  26. self.altitude.text = String(location.altitude)
  27. self.course.text = String(location.course)
  28. self.speed.text = String(location.speed)
  29. CLGeocoder().reverseGeocodeLocation(location){ (placemarks, error) in
  30. if error != nil{
  31. print(error)
  32. }
  33. else{
  34. if let placemark = placemarks?[0]{
  35. var address = ""
  36. if placemark.subThoroughfare != nil{
  37. address += placemark.subThoroughfare! + " "
  38. }
  39. if placemark.thoroughfare != nil{
  40. address += placemark.thoroughfare! + "\n"
  41. }
  42. if placemark.subLocality != nil{
  43. address += placemark.subLocality! + "\n"
  44. }
  45. if placemark.subAdministrativeArea != nil{
  46. address += placemark.subAdministrativeArea! + "\n"
  47. }
  48. if placemark.postalCode != nil{
  49. address += placemark.postalCode! + "\n"
  50. }
  51. if placemark.country != nil{
  52. address += placemark.country! + "\n"
  53. }
  54. self.add.text = address
  55. }
  56.  
  57. }
  58. }
  59. }
  60.  
  61.  
  62. }
Add Comment
Please, Sign In to add comment