geofire-java
geofire-java copied to clipboard
Query keys within an arbitrary shape?
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).
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.
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 :)
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!
Thanks for the tips jwngr, I will certainly try, but I can't guarantee anything.
The objective C implementaton for geofire has support for bounding boxes AFAIK.
@vanniktech that's good to know. We can use that code as a reference.
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.
Totally agree, bounding box and circular shape should be good enough.