使用Geofire + Firebase过滤结果 [英] Filtering results with Geofire + Firebase

查看:136
本文介绍了使用Geofire + Firebase过滤结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想弄清楚如何用Geofire过滤查询。
假设我有不同类别的餐馆。我想将该类别添加到我的查询。我现在有一种方法是用Geofire查询关键字,在每个关键字中运行for循环并获得餐厅,然后插入合适的餐厅到阵列。
这些效率很低。有没有其他的方式去做这件事?



理想情况下,我将得到过滤的结果,并且只在每个项目即将被显示时加载。

干杯!

解决方案

Firebase查询只能过滤一个条件。 Geofire已经完成了一些魔术,允许它在经度和纬度上进行过滤。为这个等式添加另一个属性可能是可能的,但是远远超出了Geofire默认处理的范围。请参阅 GeoFire:如何在查询中添加额外的条件? a>

如果您只想一次访问一个类别,则可以将餐厅放在每个类别的顶级节点中,并将Geofire指向一个类别。

  / category1 
item1
g:pns0h0mf2u
l:[-53.435719,140.808716]
item2
g:u417k3dwub
l:[56.83069,1.94822]
/ category2
item3
g:8m3r3s480
l:[30.902225, -166.66809]
/ items
item1:...
item2:...
item3:...
category1 2个项目, category2 只有一个项目。对于每个项目,我们都会看到Geofire使用的数据:地理哈希和经度和纬度。我们还保留了这三个项目的其他属性的单一列表。



但更常见的是,您只需在客户端代码中进行额外的过滤。如果你担心的是:测量它,分享代码,JSON数据和测量。

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 about this?

One way I have now is querying the key with Geofire, run the for loop through each key and get the restaurant, and insert the appropriate restaurant to the array. These seems so inefficient. Is there any other way to go about this?

Ideally I will have the filtered results, and only load each item when they're about to be shown.

Cheers!

解决方案

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.

这篇关于使用Geofire + Firebase过滤结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆