gpt4 book ai didi

swift - 如何将 MKPointAnnotation 保存到 Pars?

转载 作者:搜寻专家 更新时间:2023-11-01 05:38:34 24 4
gpt4 key购买 nike

如何在 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 中,您可以创建一个新类,将其命名为“Annotations”,添加名为“Title”、“Subtitle”、“Latitude”和“Longitude”的列,并以这种方式保存您的数据:

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

关于swift - 如何将 MKPointAnnotation 保存到 Pars?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33844398/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com