【问题标题】:how to save the co-ordinate as PFGeopoint with ios parse.com如何使用 ios parse.com 将坐标保存为 PFGeopoint
【发布时间】:2015-12-28 13:33:22
【问题描述】:

我想使用文本字段添加用户的经度和纬度,并将该值传递给 PFGeoPoint。但文本字段值在不考虑 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 中传递文本字段值。

【问题讨论】:

    标签: ios swift parse-platform coordinate-systems


    【解决方案1】:

    根据documentationPFGeoPoint 实际上是一个PFObject,它使用双精度值latitudelongitude(它们是度数)并将它们嵌入在一起。您当前正在将字符串值从文本字段转换为单个 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
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2015-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多