如何将 MKPointAnnotation 保存到 Pars?

How do I save a MKPointAnnotation to Pars?

如何在 Parse 上保存我创建的 MKPointAnnotation

@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
    }
}

您无法将 MKPointAnnotation 直接保存到 Parse。您可能希望保存其属性,例如 coordinatetitlesubtitle.

如果要保存坐标,应该将它们拆分为纬度和经度。

在 Parse 中,您可以创建一个新的 class,将其命名为 "Annotations",添加名为 "Title"、"Subtitle"、"Latitude" 和 [=25 的列=],并以这种方式保存您的数据:

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)
    }
}