Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geoqueries on boxes #100

Open
RWOverdijk opened this issue Apr 13, 2020 · 2 comments
Open

Geoqueries on boxes #100

RWOverdijk opened this issue Apr 13, 2020 · 2 comments

Comments

@RWOverdijk
Copy link

I have venues with delivery areas that I store inside of boxes. My initial plan was to find all venues that have a box I'm inside of, but unfortunately firestore doesn't allow multi-field range queries.

I want to find all the venues that have a delivery area (box) that the user is inside of. Geohashing works with points, so I'm not quite sure how to solve this.

Do you maybe have any pointers?

@IjzerenHein
Copy link
Owner

A geohash in itself is not a point but also a box. I guess you could perhaps create a field in each venue doc that holds an array of geohashes. E.g. area: ['rd56s', 'rd673', ..]. And then for instance let each geohash have a resolution of about (1000?) meters.
And then calculate the geohash (with that same 1000m resolution) at your current location and use an array-in query to get all venues.

@RWOverdijk
Copy link
Author

RWOverdijk commented Apr 14, 2020

@IjzerenHein Ah, I see. I actually meant the other way around. The user's location is a point, and I want to check inside of which boxes it belongs.

So the venue has let's say 4 polygons, but I make it a box that contains all of those polygons (using the lowest and highest lat/lon of all polygons).

image

This should make it easier to do a "fast" initial filter because traditionally I would be able to do:

const within = xLat <= lat && xLon <= lon && yLat >= lat && yLon >= lon;

And then I can filter inside of those matches (which is going to be a much smaller data set, in which I can then testing the polygons).

Which is what I do right now on the client. I just fetch everything and filter client-side. But as you can imagine that's not very scalable. I suppose it would help if I could filter this out before it gets observed but even then, there's a limit.

But because (afaik) geohash boxes are fixed in position/grid I can't really do that, can I? Or did I misunderstand what you said?

Why can't firestore just let me do multiple range clauses on multiple fields. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants