1

如何将坐标发送到 CLLocation 获取的 Parse 并将其保存为 PFGeoPoint 的纬度和经度?

我能够从 CLLocation 获取坐标,我想将其发送到 Parse。在 Parse 中,我有一个名为“coordinates”的列,类型为 PFGeoPoint,它有两个字段。现在我想将从 CLLocation 获得的坐标保存到 Parse Column 坐标。谁能帮我解决这个问题?我是 iOS 和 Parse 的新手。

4

1 回答 1

3

两步:

  1. 将 CLLocation 转换为 PFGeoPoint

    //SWIFT
    let point = PFGeoPoint(location: currentLoc)
    
    //Obj-c
    [PFGeoPoint *point = PFGeoPoint geoPointWithLocation:(PF_NULLABLE CLLocation *)location];
    
  2. 现在保存它。

    //SWIFT
    object["coordinates"] = point
    object.saveInBackgroundWithBlock {
      (success: Bool, error: NSError?) -> Void in
      if (success) {
                // The object has been saved.
      } else {
                // There was a problem, check error.description
      }
    }
    
    //Obj-c
    object["coordinates"] = point;
    [object saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
      if (succeeded) {
        // The object has been saved.
      } else {
        // There was a problem, check error.description
      }
    }];
    
于 2015-05-25T09:48:19.367 回答