我想使用textfield向用户添加经度和纬度,并将该值传递给PFGeoPoint。但是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是文本字段。我如何在PfGeopint中传递文本字段值。

最佳答案

根据documentationPFGeoPoint实际上是一种PFObject,它使用双精度latitudelongitude(均为度)并将它们嵌入在一起。当前,您正在将字符串值从文本字段转换为单个PFGeoPoints。将字符串值转换为两倍,并使用文档中描述的方法创建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
    }
}

07-26 09:38