Search by distance not working

Hello,
My AppId is 6BBA55A8-087F-EBA2-FF1B-596EB5335600
I followed the api documentation about the search by distance. I have implemented this search by distance query for mu class Event:

 val distanceQuery ="distance(${providerCoordinates.latitude}, ${providerCoordinates.longitude}, location.latitude, location.longitude) < km($maxDistance)"

Now this is request (without the website)
http://xxxx.backendless.app/data/Event?where=distance%25280.0%252C%25200.0%252C%2520location.latitude%252C%2520location.longitude%2529%2520%253C%2520km%252830%2529&loadRelations=places

But I have this error:

{
  "code": 1017,
  "message": "Where clause 'distance%280.0%2C%200.0%2C%20location.latitude%2C%20location.longitude%29%20%3C%20km%2830%29' is invalid",
  "errorData": {}
}

Is there a modification in the way to get this?

Thanks you

Hello, @Indevers.

This method has been deprecated for quite some time(more than 3 years ago).
You can use distanceOnSphere instead. All information about this method here:
https://backendless.com/docs/rest/data_spatial_retrieval_api.html#distanceonsphere-operator

Regards, Nikita.

Ok Thanks you, so I think the documentation need to be refresh.
https://backendless.com/docs/rest/data_search_by_distance.html

Is it always the same method for search by date? Or something has changed too for this other method?
Thanks you

Sorry for misleading you. Letā€™s i clarify the situation.

Only the GeoPoint service was marked as deprecated, because we had been removing it (at that time, 3 years ago). It became possible to use this function Distance both with old set of parameters and with new data types (Point, LineString, Polygon). It was made for compatibility.
After the finishing the remove process only one set of parameters was left for Distance.

Conclusion:

  1. So, the correct behavior for different SRS is provided by Distance function and only it. It also checks the input parameters for correctness according to chosen SRS.
  2. distanceOnSphere is a simple geometric function which return the arc length on the sphere surface.

ok in this case, to be clear, the method I sent you is indeed with data from a location column that takes POINT(longitude latitude) as parameters. So why doesnā€™t it work? I used a new method (POINT) with the old parameters of Distance.

Hello @Indevers

Please try to replace

distance(0.0, 0.0, location.latitude, location.longitude) < km(30)

on

distance( 'POINT(0 0)', location)<km(30)

Regards,
Volodymyr

1 Like

Thanks you it works by this way !

Hello @Volodymyr_Ialovyi is it possible too have the result sort by the shortest distance?

Hello @Indevers

Yes, something like:

/data/Event?where=dist<km(30)&property=distance( 'POINT(0 0)', location) as dist&sortBy=`dist` asc

Regards,
Volodymyr

@Volodymyr_Ialovyi I have this error
{
ā€œcodeā€: 1017,
ā€œmessageā€: ā€œWhere clause ā€˜dist<km(1000) AND property=distance( ā€˜POINT(5.8974394 49.5189477)ā€™, location) as dist AND sortBy=dist ascā€™ is invalidā€,
ā€œerrorDataā€: {}
}

and same with this
{
ā€œcodeā€: 1017,
ā€œmessageā€: ā€œWhere clause ā€˜dist<km(1000) &property=distance( ā€˜POINT(5.8974394 49.5189477)ā€™, location) as dist&sortBy=dist ascā€™ is invalidā€,
ā€œerrorDataā€: {}
}

Hello @Indevers

Try:

GET <host>/<appId>/<apiKey>/data/Event?where=dist%3Ckm(2000)&property=distance(%20'POINT(0%200)'%2C%20location)%20as%20dist&sortBy=%60dist%60%20desc

or

Regards,
Volodymyr

1 Like