Support Topics Documentation Slack YouTube Blog

Search GeoPoint in radius + filter by parent parameter

(Bugdroid) #1

Lets take as example the following schema on Backendless side:
Entity: Restaurant
Params: Name, FoodTypeFk (relationship), Rate, Location (relationship GeoPoint).
Entity: FoodType
Params: type(String)
GeoPoint class:
Params: lat, long
Metadata: nothing at the moment.
Now I need to query the following:
-> Search restaurants in a radius of 20km (example)
-> Restaurante must have [FoodTypeFk].type = ‘Italian’
How can I combine this two criteria in one REST call?
I also tried to add as GeoPoint metadata the foreign key to Restaurant, but then I still don’t know how to query for the food type.
Is it possible to do this in one REST request?

(Bugdroid) #2

I just found out this related topic:

Alexandr Navara says:
“2. This issue occurs when searching through geo with clauses which includes deep relations. For example, “rooms.objectId=<room_id>” would work well, but “<company_id>” would not. I’ve already opened an internal task for this bug and we’re working on it.”

Can someone update me if this bug is solved? I get the following error on console:
“Internal server error with id 4DCEDC22-C3CF-0554-FF37-0B95197BED00”

(Ilya Veklenko) #3

Hi Bugdroid,
Please, try to make request to your table ‘Restaurant’ with the next where clause:
distance( [Latitude], [Longitude], Location.latitude, Location.longitude ) < km(20) and FoodTypeFk.type = ‘Italian’
Don’t forget to replace [Latitude] and [Longitude] to your coordinate.

Regards Ilya

(Bugdroid) #4

Worked like a charm. Thanks :slight_smile:

And like that i don’t need to set any reference inside GeoPoint metadata.
If someone has the same problem don’t forget to encode the query following Where clause.