我想使用textfield添加来自用户的经度和纬度,并且该值传入PFGeoPoint.But Textfield值是不考虑PFGeoPoint的字符串。我的代码是:
@IBOutlet weak var latitue_filed: UITextField!
@IBOutlet weak var longitudead: UITextField!
let lati : = (latitue_filed.text as? PFGeoPoint)!
let lon : = (longitudead.text as? PFGeoPoint)!
let myGeoPoint = PFGeoPoint(latitude: lat, longitude: lon)
posts["location"] = myGeoPoint
posts.saveInBackgroundWithBlock {
(success: Bool, error: NSError?) -> Void in
if (success) {
// The object has been saved.
} else {
// There was a problem, check error.description
}
}
posts.saveInBackground()`
这里latitue_filed和longitudead是textfield。如何在PfGeopint中传递文本字段值。
答案 0 :(得分:2)
根据documentation,PFGeoPoint
实际上是PFObject
,它使用双精度latitude
和longitude
(都是度数)并将它们嵌在一起。您当前正在将字符串值从文本字段转换为单个PFGeoPoints
。将字符串值转换为double,并使用文档中描述的方法创建PFGeoPoint
。
let lati = Double(latitue_filed.text)
let lon = Double(longitudead.text)
let myGeoPoint = PFGeoPoint(latitude: lat, longitude: lon)
posts["location"] = myGeoPoint
posts.saveInBackgroundWithBlock {
(success: Bool, error: NSError?) -> Void in
if (success) {
// The object has been saved.
} else {
// There was a problem, check error.description
}
}