0

Working with react native, I want to fetch places in a specific area. In the Firebase databse I have the filed "longitude" and the field "latitude".

What I'm doing now does not work:

database()
   .ref()
   .child('places')
   .orderByChild('longitude')
   .startAt(min_longitude)
   .endAt(max_longitude)
   .then(fetchResp => {
      return fetchResp.json();
    })
   .then(fetchJsonResp => {
      resolve(fetchJsonResp);
   })

Any idea? What am I doing wrong?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
mtoninelli
  • 686
  • 1
  • 6
  • 21
  • Add ur database – Peter Haddad Feb 10 '20 at 15:48
  • In addition to seeing your database, it would also help to know what doesn't work about this code. It's typically easiest to see that if you `console.log()` the relevant values, then include the output you get in your question, as well as the output you're looking for. – Frank van Puffelen Feb 10 '20 at 16:03
  • In general though, to [query for nearby nodes with the Firebase Realtime Database](https://stackoverflow.com/search?q=%5Bfirebase-realtime-database%5D+query+nearby), you'll want to use GeoFire: https://stackoverflow.com/questions/43357990/query-for-nearby-locations/43358909#43358909 – Frank van Puffelen Feb 10 '20 at 16:05

1 Answers1

0

The query correct is this one:

database()
   .ref()
   .child('places')
   .orderByChild('longitude')
   .startAt(min_longitude)
   .endAt(max_longitude)
   .once('value')
   .then(fetchResp => {
      return fetchResp.json();
    })
   .then(fetchJsonResp => {
      resolve(fetchJsonResp);
   })

the .once('value') was missing.

mtoninelli
  • 686
  • 1
  • 6
  • 21
  • I'm parsing first the longitude on the db and from them filter the elements in latitude. If there is a way to fetch it directly to the db I would like to know. – mtoninelli Feb 11 '20 at 04:38