ios - 快速将 PFGeoPoint 纬度和经度从解析转换为 CLLocation 纬度和经度

标签 ios xcode swift parse-platform cllocation

我正在尝试从解析后端查询坐标数组(纬度和经度)。然后将它们用作 map 上的注释。虽然一旦我从解析中查询,我不知道如何将坐标转换为 CLLocation。

查询时使用的代码:

var usersLocations = [Double]()

 override func viewDidLoad() {
        super.viewDidLoad()

        PFGeoPoint.geoPointForCurrentLocationInBackground { (geopoint: PFGeoPoint!, error: NSError!) -> Void in

            var query = PFUser.query()
            query.whereKey("location", nearGeoPoint: geopoint, withinMiles: 1)
            query.limit = 10
            var users = query.findObjects()

            for user in users {

                self.usersLocations.append(user["location"] as Double)
            }


            self.currentUsersPoint()

        }
    }

然后是用于尝试将坐标数组放入 CLLocation 的代码。

var latitude:CLLocationDegrees = usersLocation.coordinate.latitude

var longitude:CLLocationDegrees = usersLocation.coordinate.longitude

我知道这有点困惑,我真的不确定,因为我对 swift 和编程还是新手,所以很难解决这一切。如果有人能提供帮助,我们将不胜感激。

最佳答案

假设 usersLocation.coordinatePFGeoPoint,您可以使用我为我的项目之一创建的以下扩展:

extension PFGeoPoint {
  public var cllocation: CLLocation {
    get {
      return CLLocation(latitude: latitude, longitude: longitude)
    }
  }
}

然后,以下内容应该可以工作(location 将是一个 CLLocation 对象)。

var location = usersLocation.coordinate.cllocation

关于ios - 快速将 PFGeoPoint 纬度和经度从解析转换为 CLLocation 纬度和经度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27756940/

相关文章:

ios - 如何在 iOS 中保存 PWA 状态

ios - 在 uitableviewcell 中实现视频的最佳方式是什么?

iOS 应用程序验证错误

macos - 使用 swift 为 NSTextView 设置默认字体

ios - NSTimer 和动画同步

ios - iPhone 上的 Safari 浏览器 : Can I close the oauth browser tab?

ios - swift bringSubViewToFront 不工作

ios - 当我使用自动布局选择每个单元格的高度(因此它们是动态的)时,它通常可以工作,但有些单元格有点短。为什么是这样?

ios - NSOperationQueue 中的 dispatch_after 等价物

ios - 带按钮的可滚动菜单部分