【问题标题】:CloudKit locations closest to point离点最近的 CloudKit 位置
【发布时间】:2015-06-28 10:40:41
【问题描述】:

我正在寻找一个 CloudKit 查询,它可以返回我的位置最近的对象,按距离排序。现在我可以得到离我的点一定距离内的位置。

NSPredicate(format: "distanceToLocation:fromLocation:(%K,%@) < %f","Location",location,radiusInKilometers)

但这不是我需要的。我正在寻找的是从最近的位置排序的位置,对我来说半径无关紧要,因此使用此查询然后在我的设备上对结果进行排序的解决方案对我不利。有什么帮助吗?

【问题讨论】:

    标签: ios nspredicate core-location cloudkit


    【解决方案1】:

    您可以在 sortDescriptors 中使用 CKLocationSortDescriptor 并将其与 resultsLimit 结合使用。这将让您按最接近您提供的点的位置进行排序,并获得特定数量的结果(例如 5 个)。

    queryOperation.sortDescriptors = [CKLocationSortDescriptor(key: "location", relativeLocation: location)]
    queryOperation.resultsLimit = 5
    

    【讨论】:

      猜你喜欢
      • 2020-10-02
      • 2018-06-11
      • 1970-01-01
      • 2014-10-08
      • 1970-01-01
      • 1970-01-01
      • 2016-07-06
      • 2023-03-19
      • 2014-02-12
      相关资源
      最近更新 更多