swift - 数据未添加到 Parse 中?

标签 swift parse-platform

我正在尝试将坐标数据发送到 Parse 中的云,但由于某种原因我无法做到这一点。我的所有字段名称都是正确的。

这里是字段: enter image description here

坐标未定义,但其余都可以。 这是我的代码来推送它:

class AddYourOwnCarWash : UIViewController
{
    var servicedownpicker : DownPicker!
    var ratingdownpicker : DownPicker!
    var carGeoPoint = PFGeoPoint()


   let geocoder = CLGeocoder()
    geocoder.geocodeAddressString(addresstextfield.text!){
        placemark, error in
        if let error = error {
            self.showAlert("ERROR", message: error.localizedDescription)
            return
        }
        //self.activityIndicator.startAnimating()
        if let  placemark = placemark{
            if placemark.count > 0 {
                let placemark = placemark.first!
                let coordinates:CLLocationCoordinate2D = placemark.location!.coordinate
                if let country = placemark.country, state = placemark.administrativeArea{
                    if let city = placemark.locality{
                       carwashobject["address"] = "\(city), \(state), \(country)"
                        print(coordinates.latitude)
                        print(coordinates.longitude)

                        self.carGeoPoint.latitude = coordinates.latitude
                        self.carGeoPoint.longitude = coordinates.longitude
                        carwashobject["coordinate"] = self.carGeoPoint

                        //self.stopActivityIndicator()
                    }else {
                         carwashobject["address"] = "\(state), \(country)"
                         carwashobject["coordinate"] = self.carGeoPoint
                        //self.stopActivityIndicator()
                    }
                } else {
                    self.showAlert("ERROR", message:"Be more specific in location")
                }
            } else {
                self.showAlert("ERROR", message:"Unable to find location")
            }
        } else {
            self.showAlert("ERROR", message: "Unable to find location")
        }
    }
    carwashobject["car"] = cartextfield.text
    carwashobject["price"] = Double(pricingtextfield.text!)
    carwashobject["service"] = servicestextfield.text
    carwashobject["rating"] = Double(ratingtextfield.text!)

    carwashobject.saveInBackgroundWithBlock { (success: Bool, error: NSError?) -> Void in
        print("Object has been saved.")

    }

     performSegueWithIdentifier("backtomain", sender: self)
}

enter image description here

坐标.纬度和坐标.经度不为零 github:https://github.com/ariff20/WashAndShine

那么为什么没有被添加呢?

最佳答案

使用自己的类进行本地化解析,例如:

let point = PFGeoPoint(latitude:40.0, longitude:-30.0)

要进行编辑,您可以尝试以下操作:

class ViewController: UIViewController{
     var carGeoPoint = PFGeoPoint()

.......

然后在你的函数中:

@IBAction func addcarwash(sender: AnyObject)
{
    var carwashobject = PFObject(className: "CarWash")
    let locManager = CLLocationManager()
   print(nametextfield.text)
    print(addresstextfield.text)
    print(cartextfield.text)
    print(pricingtextfield.text)
    print(servicestextfield.text)
    print(ratingtextfield.text)
    locManager.requestWhenInUseAuthorization()
    carwashobject["name"] = nametextfield.text
    carwashobject["address"] = addresstextfield.text
    let geocoder = CLGeocoder()
    geocoder.geocodeAddressString(addresstextfield.text!){
        placemark, error in
        if let error = error {
            self.showAlert("ERROR", message: error.localizedDescription)
            return
        }
        //self.activityIndicator.startAnimating()
        if let  placemark = placemark{
            if placemark.count > 0 {
                let placemark = placemark.first!
                let coordinates:CLLocationCoordinate2D = placemark.location!.coordinate
                if let country = placemark.country, state = placemark.administrativeArea{
                    if let city = placemark.locality{
                        carwashobject["address"] = "\(city), \(state), \(country)"
                        print(coordinates.latitude)
                        print(coordinates.longitude)

                        self.carGeoPoint.latitude = coordinates.latitude
                        self.carGeoPoint.longitude = coordinates.longitude
                        print("***********************")
                        print(self.carGeoPoint.latitude)
                        print(self.carGeoPoint.longitude)
                        carwashobject["coor"] = self.carGeoPoint
                        carwashobject["car"] = cartextfield.text
                        carwashobject["price"] = Double(pricingtextfield.text!)
                        carwashobject["service"] = servicestextfield.text
                        carwashobject["rating"] = Double(ratingtextfield.text!)

                        carwashobject.saveInBackgroundWithBlock { (success: Bool, error: NSError?) -> Void in
                            print("Object has been saved.")

                        }

                        //self.stopActivityIndicator()
                    }else {
                        carwashobject["address"] = "\(state), \(country)"
                        carwashobject["coor"] = self.carGeoPoint
                        //self.stopActivityIndicator()
                    }
                } else {
                    self.showAlert("ERROR", message:"Be more specific in location")
                }
            } else {
                self.showAlert("ERROR", message:"Unable to find location")
            }
        } else {
            self.showAlert("ERROR", message: "Unable to find location")
        }
    }



     performSegueWithIdentifier("backtomain", sender: self)
}

关于swift - 数据未添加到 Parse 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35068549/

相关文章:

swift - 删除命令不适用于 NSTextField

ios - 如何在 Swift 中将 plist 作为字典获取?

ios - Swift 中的 POST 参数

ios - 解析没有匹配项的 getObjectInBackgroundWithId 返回

ios - PF ImageView 不适用于 PF CollectionViewCell 的子类

ios - 在VC上快速拖动两个 View

ios - 自定义 UISearchController 动画

javascript - 获取解析分析自定义仪表板

android - 增加推送通知数量

Swift Parse 在注册时不显示错误消息