0

The kind of data I am working with:

"places" : {
    "place_1" : {
        "lat" : 10,
        "lng" : 20,
    },
    "place_2" : {
        "lat" : 12,
        "lng" : 22
    },
    "place_3" : {
        "lat" : 15,
        "lng" : 25
    }
}

I want to query for places which are near to a given location i.e. in +-2 lat lng of the some coordinate. Lets say my location is lat=11,lng=23. So want to do something like

placesRef.orderByChild("lat")
    .startAt(9)
    .endAt(13)
    .orderByChild("lng")
    .startAt(21)
    .endAt(25)

This would return me "place_2". But Firebase doesn't support ordering for multiple children, so I want some alternate way in which I can accomplish this task. I cannot think of a combined key which would help me query the way I want.

udiboy1209
  • 1,472
  • 1
  • 15
  • 33
  • You've already found that Firebase Database queries can only order/filter on a single property. In many cases you can combine the values you want to filter on into a single (synthetic) property, as I show in my answer here: http://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase. Your requirement for latitude and longitude is a special variation of this, which is handled nicely by the [GeoFire library](https://github.com/firebase/geofire-js). – Frank van Puffelen Sep 21 '17 at 11:12
  • Ahh I should have googled about location querying directly! Thanks @FrankvanPuffelen – udiboy1209 Sep 21 '17 at 11:22

0 Answers0