title: iOS Swift: Request user location
body: <p>I'm a beginner in iOS Swift and writing iOS Swift code and using UIWebView to load my web page.</p>
  
  <p>And my web page will <strong>ask user to enable the user location</strong>.</p>
  
  <p>I would like to do the similar behavior in iOS Swift code (popup an dialog and say something like "TestApp would like to access your location. Would you agree?")</p>
  
  <p>I'm running on Simulator and I failed while using CLLocationManager</p>
  
  <p>The following is my Swift code</p>
  
  <pre><code>import UIKit
  import CoreLocation
  
  class ViewController: UIViewController, CLLocationManagerDelegate {
  @IBOutlet weak var customWebView: UIWebView!
  
  
  override func viewDidLoad() {
      super.viewDidLoad()
      // Do any additional setup after loading the view, typically from a nib.
      if let url = NSURL(string: "http://ctrlq.org/maps/where/") {
          let request = NSURLRequest(URL: url)
          customWebView.loadRequest(request)
  
          let locationManager = CLLocationManager()
          locationManager.delegate = self
          locationManager.desiredAccuracy = kCLLocationAccuracyBest
          locationManager.requestAlwaysAuthorization()
          locationManager.startUpdatingLocation()
  
      }
  }
  
  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
      // Dispose of any resources that can be recreated.
  }
  
  }
  </code></pre>
  
  <p>Anyone knows how to request location?</p>
  
  <p>Thanks in advance.</p>
  
  <p>Eric</p>