iOS 9: Getting single location update with requestLocation()

Apple added new API to CoreLocation framework. One of the available methods is requestLocation() which allow to get single location update.

This is nice for apps that need just a quick fix to work. You can call the method and in few seconds get user’s location and location manager automatically stops.

import UIKit
import CoreLocation

class ViewController: UIViewController, CLLocationManagerDelegate {

    private var locationManager = CLLocationManager()

    override func viewDidLoad() {
        locationManager.delegate = self

    @IBAction func getFixPressed(sender: AnyObject) {

    // MARK: CLLocationManagerDelegate
    func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

    func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {

To use it you must implement locationManager:didUpdateLocations: and locationManager:didFailWithError: methods of CLLocationManagerDelegate. Failing method is called when location manager cannot get update or when permissions are not granted or when location cannot be determined in some time (managed by the system).


This is nice addition to Core Location. Unfortunately it is available only in iOS 9. Code is cleaner and you can not worry about stopping location updates.