【发布时间】:2013-06-26 19:40:59
【问题描述】:
由于 firebase 不支持任何空间索引,所以我使用 geohash,有人在这里建议。 Geohash 正在使用字符来查找附近。
假设我在 firebase 中有 w22qt4vhye1c w99qt4vdf4vc w22qt4vhzerct geohash 存储,我只想查询接近 w22qt4 的 geohash。
怎么做?
我知道 firebase 有 startAt。我试过了,还是不行。
更新
将 geohash 存储到 firebase
//Encode lat lng, result w22qt4vhye1c3
var geoHashLatLng = encodeGeoHash(lat,lng);
firebaseRef.child('/geohash/' + geoHashLatLng).set(id);
所以在 json 中
root
- geohash
- w22qt4vhye1c3
- id
- z99qt4vdf4vc
- w22qt4vhzerct
我的问题在这里。
我只想查询从字符w22qt4 开始的geohash。我们可以在 firebase 中做到这一点吗?
更新 2
startAt() 似乎不是以...开头的字符查询
示例:我有以下 gehash
geohash 节点
geohash
- a123
- a333
- b123
- c123
- d123
使用以下代码
var firebaseRef = new Firebase('https://test.firebaseio.com');
var query = firebaseRef.child('/geohash').startAt(null, 'a');
query.on('child_added', function(snapshot) {
console.log(snapshot.name());
});
会得到这个结果
startAt(null, 'a') //return a123, a333, b123, c123, d123
startAt(null, 'c123') //return c123, d123
startAt(null, 'd') //return d123
我的预期结果
startAt(null, 'a') //return a123, a333
startAt(null, 'c123') //return c123
startAt(null, 'd') //return d123
我的猜测,startAt() 将按顺序查询 26 个字母但不匹配。 那么,我可以在 firebase 中做什么,以便获得上述预期结果?
【问题讨论】:
-
您能否提供您正在尝试的代码 sn-p,以便我提供更有意义的反馈?
-
@AndrewLee 嗨,我刚刚更新了我的问题,请看一下。
-
您可以使用“endAt”在特定键处结束。请参阅下面对我的帖子的修改。
标签: firebase