数据没有添加到Parse?

时间:2016-01-28 17:53:42

标签: 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

coordinates.latitude和coordinates.longitude不是零 github:https://github.com/ariff20/WashAndShine

那么为什么不加入?

1 个答案:

答案 0 :(得分:1)

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

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