The front end is an iOS app using swift.
I just added 2 new fields to my Order class to store the users current latitude and longitude:
- userLat
- userLong
Here is my class definition
class Order: NSObject
{
var objectId: String?
var user: BackendlessUser?
var userLat: Double = 0.0
var userLong: Double = 0.0
var price: Double = 0.0
var paymentProcessingStatus = "Unprocessed"
override init()
{
super.init()
}
init(user: BackendlessUser)
{
super.init()
self.user = user
}
}
I set the userLat/userLong values using CLLocation lat/long then save the object to backendless with following:
func createOrder(order: Order, completion: (Order?,Fault?) -> Void)
{
let dataStore = backendless.data.of(Order.ofClass())
print(order.userLat)
dataStore.save(
order,
response: { (result: AnyObject!) -> Void in
print("Create order response received")
let savedOrder = result as! Order
print("Order saved: \(savedOrder.user!.email)")
completion (savedOrder, nil)
},
error: { (error: Fault!) -> Void in
print("server reported error: \(error)")
completion(nil, error)
})
}
When I print userLat at line 5 I get the correct value for userLat, but when I check the value in Backendless the userLat and userLong values are switched. This is very strange to me as obviously there’s no way my code has transformed the values since the asynch save call occurs immediatley after printing the value so the order object I sent to backendless must have the correct userLat value.
At first my only problem was the switched values. I tried going into the backendless schema editor and removing the userLat/userLong columns in case something weird had occurred when they were created then tried to save a new order. I now still have the switched values problem but theres an additional problem. My userLat value is now getting truncated at before the decimal point. I had a similar problem with Backendless truncating Double values before: http://support.backendless.com/t/double-value-is-being-rounded-to-nearest-value
In the previous case I was advised to switch the data type to int then back to double. Last time that didn’t work so I simply created a new app in backendless and started using that which fixed my problem. I tried it again this time and no luck, the updated data type doesn’t even save.
I attached a screenshot of the problem fields, as you can clearly see the userLat has 14 digits after the decimal point, whereas the userLong has none. Those two fields should look the same, and again for some reason those two values are being switched.