转换PFGeoPoint为字符串错误
问题描述:
我绑在解析服务器保存PFGeoPoint用下面的代码:转换PFGeoPoint为字符串错误
var coordinates = PFGeoPoint (latitude: (newCoordinate2.latitude), longitude:(newCoordinate2.longitude))
var aboutSpot = PFObject(className: "spotdetail")
aboutSpot["name"] = "name"
aboutSpot [PFGeoPoint] = coordinates
aboutSpot.saveInBackgroundWithBlock { (succes, error) -> Void in
print("separate name and geopoint have been saved")
}
,我得到以下信息:
swift cannot convert value of type `(PFGeoPoint).type (aka 'PFGeoPoint.type`) to expected argument type 'String'
我可以改变,因此Xcode停止思考我想保存一个字符串?
答
我想通了,所以我在解析服务器手动添加一列,然后改变了这样的代码,它现在的作品,感谢帮助了
var coordinates = PFGeoPoint (latitude: (newCoordinate2.latitude), longitude:(newCoordinate2.longitude))
var aboutSpot = PFObject(className: "spotdetail")
aboutSpot["name"] = "replaceNow"
aboutSpot ["PFGeoPoint"] = coordinates
aboutSpot.saveInBackgroundWithBlock { (succes, error) -> Void in
print("separate name and geopoint have been saved")
}
答
尝试先将经度和纬度作为double
,然后使用distanceInKilometersTo
或distanceInMilesTo
。
希望这会有所帮助。
+0
感谢您的帮助,我只是想出了它。 –
相当肯定的Xcode不只是* *想你'正试图保存一个字符串。 *你正试图保存一个字符串。你能打印aboutSpot [“name”]吗?还是会抛出错误呢? – LinusGeffarth
感谢您的帮助,我只是想出了它。 –