how can I send coordinates to parse and save it as

2019-04-02 09:27发布

How can i send coordinates to Parse fetched by CLLocation and save it there as PFGeoPoint's latitude and longitude?

I am able to get the coordinates from CLLocation and I want to send it to Parse. In Parse I have a column named "coordinates" of type PFGeoPoint which has two fields.Now I want to save the coordinates which I have got from CLLocation to Parse Column coordinates. can anyone please help me with this? I am new to iOS and Parse.

1条回答
爷的心禁止访问
2楼-- · 2019-04-02 09:55

Two steps:

  1. Convert CLLocation to PFGeoPoint

    //SWIFT
    let point = PFGeoPoint(location: currentLoc)
    
    //Obj-c
    [PFGeoPoint *point = PFGeoPoint geoPointWithLocation:(PF_NULLABLE CLLocation *)location];
    
  2. Now save it.

    //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
      }
    }];
    
查看更多
登录 后发表回答