Swift basics-Positioning
//// ViewController. swift // JieCoreLocation /// Created by jiezhang on 14-10-4. // Copyright (c) jiezhang. all rights reserved. // import UIKitimport CoreLocationclass ViewController: UIViewController, CLLocationManagerDelegate {required init (coder aDecoder: NSCoder) {super. init (coder: aDecoder)} @ IBOutlet weak var longitudeTxt: UITextField! @ IBOutlet weak var latitudeTxt: UITextField! @ IBOutlet weak var HeightTxt: UITextField! @ IBOutlet weak var addressTxt: UILabel! Var currLocation: CLLocation! // Address decompilation error. I am simulating @ IBAction func reverseGeocode (sender: AnyObject) {var geocoder = CLGeocoder () var p: CLPlacemark on the simulator? Geocoder. reverseGeocodeLocation (currLocation, completionHandler: {(placemarks, error)-> Void in if error! = Nil {println ("reverse geodcode fail: \ (error. localizedDescription) ") return} let pm = placemarks as [CLPlacemark] if (pm. count> 0) {p = placemarks [0]? CLPlacemark println (p)} else {println ("No Placemarks! ")} // Used to locate the service management class. It can provide us with location information and height information, or monitor the device's entry or exit from a certain area, you can also obtain the operation direction of the device. let locationManager: CLLocationManager = CLLocationManager () override func viewDidLoad () {super. viewDidLoad () locationManager. delegate = self // The highest precision locationManager when the device is powered by a battery. desiredAccuracy = kCLLocationAccuracyBest // precise to 1000 m, distance filter, defines the minimum distance from the device to obtain location information after moving locationManager. distanceFilter = kCLLocationAccuracyKilometer} override fu Nc viewWillAppear (animated: Bool) {locationManager. startUpdatingLocation () println ("")} override func viewWillDisappear (animated: Bool) {locationManager. stopUpdatingLocation () println ("")} func locationManager (manager: CLLocationManager !, DidUpdateLocations locations: [AnyObject]!) {CurrLocation = locations. last as CLLocation longitudeTxt. text = "\ (currLocation. coordinate. longpolling) "latitudeTxt. text = "\ (currLocation. coordinate. latitude) "HeightTxt. text = "\ (currLocation. altitude) "} func locationManager (manager: CLLocationManager !, DidFailWithError error: NSError !) {Println (error)} override func didReceiveMemoryWarning () {super. didReceiveMemoryWarning ()}}