title: Core Location in Swift
body: <p>This is sample code. <code>NSLocationAlwaysUsageDescription</code> key in Info.plist installed. All work fine - program receives the coordinates.... displays them.....</p>
  
  <p>And it continues to update them permanently! In the case of the iOS simulator - it is not critical, but in the case of a real application it is very quickly drain the battery. How to make an application launched Core Location, received location, and got shut down Core Location?</p>
  
  <pre><code>import UIKit
  import CoreLocation
  
  class ViewController: UIViewController, CLLocationManagerDelegate {
  
  @IBOutlet var locLabel: UILabel
  @IBOutlet var latLabel: UILabel
  @IBOutlet var lonLabel: UILabel
  
  var locationManager = CLLocationManager()
  
  override func viewDidLoad() {
      super.viewDidLoad()
  }
  
  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
  }
  
  @IBAction func locButton(sender: AnyObject) {
      locationManager.delegate = self
      locationManager.desiredAccuracy = kCLLocationAccuracyBest
      locationManager.requestAlwaysAuthorization()
      locationManager.startUpdatingLocation()
  }
  
  func locationManager(manager:CLLocationManager, didUpdateLocations locations:AnyObject[]) {
      println("locations = \(locationManager)")
      var latValue = locationManager.location.coordinate.latitude
      var lonValue = locationManager.location.coordinate.longitude
      latLabel.text = String(latValue)
      lonLabel.text = String(lonValue)
      locLabel.text = "success"
  }
  </code></pre>
  
  <p>}</p>