geofire-java icon indicating copy to clipboard operation
geofire-java copied to clipboard

Query keys within an arbitrary shape?

Open janakagamini opened this issue 8 years ago • 8 comments

This might be a stretch, but in addition to querying for keys within a radius, will it be possible (in the future perhaps) to query for keys within an arbitrary shape (possibly defined as a list of GeoLocations)?

E.g. usage: Check if a point is within a certain city (given that I know a list of GeoLocations that outlines the city).

janakagamini avatar Apr 05 '16 07:04 janakagamini

Thanks for the feature request! It is pretty much equivalent to https://github.com/firebase/geofire-js/issues/46. Unfortunately, I don't see this happening any time soon unless someone from the community wants to take a crack at it and send us a PR.

jwngr avatar Apr 05 '16 16:04 jwngr

Yes, exactly that. I'll give it a try. From a cursory glance at the code it seems I should probably be looking at private boolean locationIsInQuery(GeoLocation location) @ GeoQuery.java

Shout out if I'm way off. Thanks :)

janakagamini avatar Apr 06 '16 02:04 janakagamini

Yup, that is the right place. Thanks for taking a crack at this!

A couple notes:

  • You will also need a new constructor since the current one just takes a center and radius. You will need a constructor which takes in the coordinates for the arbitrary shape of our GeoQuery.
  • You will need to update locationIsInQuery() to do something different depending on if it's a circular GeoQuery or a polygonal GeoQuery. Defining Firebase queries for a polygonal GeoQuery will be tough (which is why we haven't tackled it yet) and may end up be wildly inefficient, but hopefully you can figure out the math behind it!

jwngr avatar Apr 06 '16 15:04 jwngr

Thanks for the tips jwngr, I will certainly try, but I can't guarantee anything.

janakagamini avatar Apr 09 '16 02:04 janakagamini

The objective C implementaton for geofire has support for bounding boxes AFAIK.

vanniktech avatar Nov 27 '17 15:11 vanniktech

@vanniktech that's good to know. We can use that code as a reference.

samtstern avatar Nov 27 '17 16:11 samtstern

I think it would be reasonable to try and support bounding boxes, but I don't think we should get into the math of doing arbitrary polygonal geo computations in this library. It's probably much better for everyone to just use a bounding box and then use some client-side logic to narrow that down to the polygon.

samtstern avatar Nov 27 '17 16:11 samtstern

Totally agree, bounding box and circular shape should be good enough.

vanniktech avatar Nov 27 '17 16:11 vanniktech