Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

175
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda