Backendless Support
 
Answered

Search GeoPoint in radius + filter by parent parameter

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?

Leave a Comment

Comments (3)

photo
1

I just found out this related topic: http://support.backendless.com/topic/how-to-get-filtered-and-sorted-by-a-distance-data-from-a-data-table

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 "rooms.company.objectId=<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"

photo
1

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

photo
1

Worked like a charm. Thanks :)

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.

photo