由於firebase不支持任何空間索引,因此我使用geohash這裏有人建議。 Geohash正在使用字符來查找附近。如何查詢與匹配字符串前綴的鍵相關的Firebase
所以我們說,我有火力w22qt4vhye1c
w99qt4vdf4vc
w22qt4vhzerct
地理散列存儲和我只取地理散列接近w22qt4
查詢。
如何做到這一點?
我知道firebase有startAt。我試過但沒有工作。
UPDATE
存儲地理散列以火力
//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
- 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中做些什麼,以便我可以在上面獲得預期結果?
你能提供你正在嘗試的代碼片段,所以我可以提供更有意義的反饋嗎? –
@AndrewLee嗨,我剛剛更新了我的問題,請看看。 – vzhen
您可以使用「endAt」以特定鍵結束。請參閱下面我的帖子的編輯。 –