如何发送坐标进行解析并将其保存为解析PFGeopoint

时间:2015-05-25 09:42:14

标签: ios parse-platform coordinates cllocation parse-framework

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

我能够从CLLocation获取坐标,我想将它发送给Parse。在Parse中,我有一个名为“坐标”的列,类型为PFGeoPoint,它有两个字段。现在我想保存从CLLocation到Parse Column坐标的坐标。 有人可以帮我这个吗? 我是iOS和Parse的新手。

1 个答案:

答案 0 :(得分: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
      }
    }];