2

How do I save on Parse a MKPointAnnotation that I created?

@IBAction func salvaRicordo(sender: AnyObject) {
    let puntoRicordo = MKPointAnnotation()
    puntoRicordo.coordinate = posizioneUtente
    puntoRicordo.title = nomeField.text
    puntoRicordo.subtitle = descrizioneField.text
    self.myMapView.addAnnotation(puntoRicordo)
    print("PointAnnotation creato")
    puntoRicordo.saveInBackgroundWithBlock {
    (success: Bool, error: NSError?) -> Void in
    if (success) {
        // The object has been saved.
    } else {
        // There was a problem, check error.description
    }
}
Cesare
  • 9,139
  • 16
  • 78
  • 130
Bistecca
  • 23
  • 2

1 Answers1

0

You can't save a MKPointAnnotation to Parse directly. You may want to save its properties such as coordinate, title and subtitle.

If you want to save coordinates, you should split them into latitudes and longitudes.

In Parse you can create a new class, call it "Annotations", add columns named "Title", "Subtitle", "Latitude" and "Longitude", and save your data this way:

let myObject = PFObject(className: "Annotations")
myObject["Title"] = nomeField.text
myObject["Subtitle"] = descrizioneField.text
myObject["Latitude"] = puntoRicordo.latitude
myObject["Longitude"] = puntoRicordo.longitude
myObject.saveInBackgroundWithBlock {
    (success: Bool, error: NSError?) -> Void in
    if (success) {
        print("Data saved to Parse.")
    } else {
        print(error)
    }
}
Cesare
  • 9,139
  • 16
  • 78
  • 130