Filtering results with Geofire + Firebase

后端 未结 2 1252
礼貌的吻别
礼貌的吻别 2020-12-01 20:37

I\'m trying to figure out how to query with filter with Geofire. Suppose I have restaurants with different category. and I want to add that category to my query. How do I go

2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-01 21:01

    Firebase queries can only filter by one condition. Geofire already does quite some "magic" to allow it to filter on both longitude and latitude. Adding another property to that equation might be possible, but is well beyond what Geofire handles by default. See GeoFire: How to add extra conditions within the query?

    If you only ever want to access one category at a time, you can put the restaurants in a top-level node per category and point Geofire to one category.

    /category1
        item1
            g: "pns0h0mf2u"
            l: [-53.435719, 140.808716]
        item2
            g: "u417k3dwub"
            l: [56.83069, 1.94822]
    /category2
        item3
            g: "8m3rz3s480"
            l: [30.902225, -166.66809]
    /items
        item1: ...
        item2: ...
        item3: ...
    

    In the above example, we have two categories: category1 with 2 items and category2 with just 1 item. For each item, we see the data that Geofire uses: a geohash and the longitude and latitude. We also keep a single list with the other properties of these 3 items.

    But more commonly, you simply do the extra filtering in client-side code. If you're worried about the performance of that: measure it, share the code, JSON data and measurements.

提交回复
热议问题