Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
Firestore - combining GeoQuery with normal queries

I am implementing an app that contains a map. In this map, the user can select its location, in order to find items of other users around his radius.

In order to do that, when a user writes an item into Firestore, I am just reverse geocoding the selected location, in a specific language (english), in order to get the name of the address (in english) and store it as a normal string field in a new Firestore doc.

Just like this:

export const GOOGLE_MAPS_GEOCODING_ENDPOINT = (
  latitude,
  longitude,
  key,
  language = "en"
) =>
  `https://maps.googleapis.com/maps/api/geocode/json?` +
    `latlng=${latitude},${longitude}&key=${key}&language=${language}`;


export default async (coordinate) => {
  const endpoint = GOOGLE_MAPS_GEOCODING_ENDPOINT(
    coordinate.latitude,
    coordinate.longitude,
    Constants.manifest.ios.config.googleMapsApiKey
  );

  const res = await fetch(endpoint);
  const data = await res.json();

  // Get the address components
  const addressComponents = data.results[0]?.address_components;

  // Build the location object
  const location = buildLocation(addressComponents);

  return location;
};

I implemented this some years ago, and I have recently read about Firestore GeoQueries (not sure if it was added the past year or recently, but I have never use it).

Currently, I am just performing queries like:

// Fetching items near me
const query = db
  .collection("items")
  .where("random", "<", randomId)
  .where("type", "==", type)
  .where("location.city", "==", city)
  .orderBy("random", "desc");

As you can see, I am using the country field to perform some kind of "GeoQuery". But I don't like the idea of having to store addresses in the database, with the restriction that, regardless of the internationalization of the app, they must be in English.

Is it currently possible to combine the Firestore GeoQuery feature to perform "complex" queries as the one I described?

I mean, getting random items near me which price is lower than X, or stuff like that (talking about latitude and longitude, not addresses).

Becuase, as I have read in the documentation, we have to order the collection by geohashes... and in my case I need to get random docs inside some bounds. So something like:

const q = db.
  .collection("items")
  .where("randomId", "<=", randomId)
  .orderBy("geohash")
  .startAt(b[0])
  .endAt(b[1]);

will not work, as the first orderBy should be "randomId". Is there any example or workaround? Should I use sub-collections (containing items with similar bounds (in a range)) instead?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!