Hi Backendless Team,
I have a problem, why does this code get an error?
This code is written half a year ago and it was working fine, suddenly we are getting errors in the where clause. Please check here is the code.
Backendless may change the distance method. So I have done with the new method but I got an Error in this too. Please resolve this as soon as possible.
In your case you didn’t pass correct arguments for distance(...) function. This function expects to receive two arguments of spatial point type but you passed 4 arguments of string type.
In case with distanceOnSphere(...) it seems to be the same situation - your location column has wrong type. It should have spatial type.
then I have read some topics regarding this topic and I got this topic.
Then I have changed my code according to new backendless changes can you please suggest to me how can I pass spatial type latitude and longitude column names in distanceOnSphere(…)?
Your new code seems to be valid. Could you please try to create the same query using REST Console?
The only thing which can case such error is invalid values which you pass using variables. If they are out of range, then this error can appear
This is very strange error because it appears in your app but doesn’t appear in my test app. At the same time if to use distance(...) function instead with the same params there will be no problem (I tried it in your app). Not sure at the current moment what exactly causes this problem.
And Can you please suggest how can I pass separate latitude and longitude columns like before I used in the distance(…)?
It is not possible to pass longitude and latitude as separate params to this function in new geolocation API. I will ask my colleagues if it possible to dynamically create spatial points in “where clause” and properties
Can you please investigate and help me resolve this issue, a few weeks ago all code working fine, and suddenly this error comes, My app features not working because of this and I have to resolve this issue as soon as possible.
Returning to your original problem for which you have created this topic.
That code, from your first screenshot, where you pass 4 params in distance(...) was removed 5 moths ago in favor of native distance function from DB. Even when it was present it was not precise. We forgot to update our documentation at that point. We a very sorry for misguiding you.
About distanceOnSphere(...) function. This function requires that your points should be in WGS84 system of coordinates while distance(...) function works with Cartesian system of coordinates. Valid values for longitude and latitude in WGS84 belong to the range [-90, 90]. In your case some of the points from location column were not valid in WGS84. Due to this you got that error “Incorrect arguments to st_distance_sphere”.
And Can you please suggest how can I pass separate latitude and longitude columns like before I used in the distance(…)?
I have got an answer from my colleagues. It is not possible with the existing means to create spatial points for “where clause” dynamically during request. You should have a column of spatial point type for queries which use geo functions.
About distanceOnSphere(...) function. This function requires that your points should be in WGS84 system of coordinates while distance(...) function works with Cartesian system of coordinates. Valid values for longitude and latitude in WGS84 belong to the range [-90, 90]. In your case some of the points from location column were not valid in WGS84. Due to this you got that error “Incorrect arguments to st_distance_sphere”.
Is there any other way to sort by distance closest to further work with the Cartesian system of coordinates? like distance() function work.
It seems that I have confused you
You can use distance(...) for this. Instead of passing to it 4 separate coordinates you should pass points. Your “where clause” will look in the next way: distance(location, 'POINT(<your longitude> <your latitude>)') <= 100000. Or if you want to define property and sort by it you can put distance(location, 'POINT(<your longitude> <your latitude>)') as dist in property definition and then sort by it. In both examples column location of Point type.