<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.10.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -",
    "watchOS: 3.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CloudKit",
  "identifier" : "/documentation/CloudKit/CKLocationSortDescriptor/init(key:relativeLocation:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "CloudKit"
    ],
    "preciseIdentifier" : "c:objc(cs)CKLocationSortDescriptor(im)initWithKey:relativeLocation:"
  },
  "title" : "init(key:relativeLocation:)"
}
-->

# init(key:relativeLocation:)

Creates a location sort descriptor using the specified key and relative location.

```
init(key: String, relativeLocation: CLLocation)
```

## Parameters

`key`

The name of the key with a <doc://com.apple.documentation/documentation/CoreLocation/CLLocation> object as its value. The key must belong to the records you’re sorting. The sort descriptor uses this key to retrieve the corresponding value from the record.

`relativeLocation`

The reference location when sorting. CloudKit sorts records according to their distance from this location.

## Discussion

During sorting, the sort descriptor computes the distance between the value in the `relativeLocation` parameter and the location value in the specified key of each record. It then sorts the records in ascending order using the distance between the two points. You can’t change the sort order.

---

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)