Retrieve users around a location

Suppose you have a relation in Users table with another table holding information about the user’s current location among with other things.
Now, if you want to search for all users and see if they are in a specific distance from a geopoint, how would you form that query?
Lets assume we have a table UserLocationInfo and that has a field currentLocation (Geopoint). In the user table you have a field userLocationInfo pointing to the UserLocation table(1:1).
I tried the following where clause (among others)
userLocationInfo.currentLocation = distance(“some latitude”,“some longitude”,“currentLocation.latitude”,“currentLocation.longitude”) <=ft(1000)
But I can not get it to work. How should we form such a query?
Regards,
George

Make sure autoload is activated on your geopoint!

Not sure if 100% correct, give it a try.

double searchFromLatitude = 0.0;
double searchFromLongitude = 0.0;
String whereClause = String.format("distance(userLocationInfo.currentLocation.latitude,%s,userLocationInfo.currentLocation.longitude,%s) < ft(1000)",searchFromLatitude,searchFromLongitude);
BackendlessDataQuery query = new BackendlessDataQuery();
Backendless.Data.of(BackendlessUser.class).find(query, new AsyncCallback&lt;BackendlessCollection&lt;BackendlessUser&gt;>() {
    @Override
    public void handleResponse(BackendlessCollection&lt;BackendlessUser&gt; backendlessUserBackendlessCollection) {
        
    }


    @Override
    public void handleFault(BackendlessFault backendlessFault) {


    }
});

This might work too…

double searchFromLatitude = 0.0;
double searchFromLongitude = 0.0;
String whereClause = String.format("distance(userLocationInfo.currentLocation.latitude,%s,userLocationInfo.currentLocation.longitude,%s) < ft(1000)",searchFromLatitude,searchFromLongitude);
BackendlessDataQuery query = new BackendlessDataQuery();
QueryOptions queryOptions = new QueryOptions();
queryOptions.addRelated("userLocationInfo");
queryOptions.addRelated("userLocationInfo.currentLocation");
Backendless.Data.of(BackendlessUser.class).find(query, new AsyncCallback&lt;BackendlessCollection&lt;BackendlessUser&gt;>() {
@Override
public void handleResponse(BackendlessCollection&lt;BackendlessUser&gt; backendlessUserBackendlessCollection) {


}


@Override
public void handleFault(BackendlessFault backendlessFault) {


}
});

That is what I was pretty much doing, I have all my related properties to auto load.

I tried what you suggested but I get the same result as before.
Either no Existing columns error, or Invalid where clause error, depending how deep I go in my relation. I will give it another try and get back.
In the meantime if anyone else has any ideas please post
Thank you in advance.

Could you show what the whereClause looks like after all the formatting is done?

Sorry Mark, I was out of the office, just got back. Here is the whereClause after the formatting

distance( 32.779108, -96.797000,userLocation.location.latitude,userLocation.location.longitude) < mi(5)

userLocation is the reference of the table connected to User table and location is the Geopoint in the userLocation table.

Regards,

George

@Mark

Hey Mark,

Any update on this?
Thank you in advance.

Regards,

George

What is “userLocation”? What does it point to?

@Mark
userLocation is a property in User table and it points to a data object UserLocation, which has a location fied (among others) )that is a Geopoint
I have the relationship in my previous post as well

This will not work. The 3rd and 4th arguments in the distance() function must point to the immediate property which referenced a GeoPoint.

@Mark,

Thank you very much for your feedback. I guess I will have to re-organize the way the tables are linked to each other, to get the the required result.

Just for future reference, it would be nice to have such a functionality if possible. It would make things work easier if you could access Geopoint relations like in other cases of Parent-Child object data relationships.

Regards,

George