<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.6.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreLocation",
  "identifier" : "/documentation/CoreLocation/CLLocationManagerDelegate/locationManager(_:didFailWithError:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Core Location"
    ],
    "preciseIdentifier" : "c:objc(pl)CLLocationManagerDelegate(im)locationManager:didFailWithError:"
  },
  "title" : "locationManager(_:didFailWithError:)"
}
-->

# locationManager(_:didFailWithError:)

Tells the delegate that the location manager was unable to retrieve a location value.

```
optional func locationManager(_ manager: CLLocationManager, didFailWithError error: any Error)
```

## Parameters

`manager`

The location manager object that was unable to retrieve the location.

`error`

The error object containing the reason the location or heading could not be retrieved.

## Discussion

If you do not implement this method, Core Location throws an exception when attempting to use location services.

The location manager calls this method when it encounters an error trying to get the location or heading data. If the location service is unable to retrieve a location right away, it reports a [`CLError.Code.locationUnknown`](/documentation/CoreLocation/CLError-swift.struct/Code/locationUnknown) error and keeps trying. In such a situation, you can simply ignore the error and wait for a new event. If a heading could not be determined because of strong interference from nearby magnetic fields, this method returns [`CLError.Code.headingFailure`](/documentation/CoreLocation/CLError-swift.struct/Code/headingFailure).

If the user denies your app’s use of the location service, this method reports a [`CLError.Code.denied`](/documentation/CoreLocation/CLError-swift.struct/Code/denied) error. Upon receiving such an error, you should stop the location service.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)