firebase / firebase-js-sdk

Firebase Javascript SDK
https://firebase.google.com/docs/web/setup
Other
4.85k stars 892 forks source link

Geo query inside specific area (bounds) with GeoPoint #4182

Closed Ruschio closed 3 years ago

Ruschio commented 3 years ago

I tried to make a query to get all docs that have a position inside boundaries (so between to points on the map), like so:

var NORTH = new firebase.firestore.GeoPoint(40, 0);
var SOUTH = new firebase.firestore.GeoPoint(35, 0);

db
  .collection('collection_name')
  .where('location', '<=', NORTH)
  .where('location', '>=', SOUTH) 

I noticed that it doesn't support yet the type of query, considering only the latitude of the GeoPoint. My question is: how about implement that feature that will simplify a lot our work? For example MongoDB already have this kind of stuff Is there another way to get only docs inside a rectangular area, without download (so spend read request) docs that i don't want to be retrieved?

Thanks for the answer

wilhuff commented 3 years ago

Even though Firestore has a GeoPoint type, we don't support any kind of geo query based on this type. See previous discussion in #826 for more details.

There are third party libraries that can be used to implement something like what you want, though we can't make make any recommendations. See https://stackoverflow.com/q/46630507 for discussions on the topic. Note that the accepted answer there includes code like what you're trying to do and this doesn't actually work. See the other answers for how others are implementing this.