1

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.

Sushrita
  • 725
  • 10
  • 29

1 Answers1

3

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
      }
    }];
    
Mika
  • 5,807
  • 6
  • 38
  • 83
  • can you please post the answer once again in Objective -C I don't know about Swift. and thank you for the response – Sushrita May 25 '15 at 10:08
  • thank you for the answer but it's saying "[Error]: The object is too large -- should be less than 128 kB. (Code: 116, Version: 1.7.2)". – Sushrita May 25 '15 at 10:42
  • Not sure but there must be doing something else going on. The code I gave you should work. It comes from the parse.com doc. – Mika May 25 '15 at 10:47
  • it's saying that the object which I am sending is more than 128kb so it can't be saved any idea how to solve this? and is there any way to send only the coordinates not the whole object of CLLocation – Sushrita May 25 '15 at 10:51
  • 1
    This is another question man... I have no idea what else is in your object... You should ask a new question. – Mika May 25 '15 at 10:52