0
votes

I have a class in parse.com called Journey, which contains an origin and a destination column. As you can't have two geopoints on one object, I've had to make these pointers to a separate Address class to store the location data.

Journey
-------
objectId
origin (Pointer to Address object)
destination (Pointer to Address object)

Address
-------
objectId
location (geopoint)
country

What I can't figure out is how to construct a geo query to find journeys with an origin near a particular geopoint.

I can easily do a geo query on the Address class and return all Address objects near a point. But this seems wasteful as some of those might be a 'destinations' rather than 'origins'. I would also need to do a separate query on the Journey class to match these Address objects to Journey origins in order to find the appropriate journey.

Is there a better way of doing this? e.g. can I query the Journey object with a geo query on the origin relation?

1

1 Answers

0
votes

Have a look at the documentation for Relational Queries:

https://parse.com/docs/rest#queries-relational

You have a where on the "origin" column and use the $inQuery operator, e.g.

where={
  "origin":{
    "$inQuery":{
      "where":{
        "location":{
          "$nearSphere": {
            "__type":"GeoPoint",
            "latitude":30.0,
            "longitude":-20.0
          }
        }
      },
      "className":"Address"
    }
  }
}