Since firebase not support any spatial indexing then I use geohash which someone advice here. Geohash is using characters to find the nearby.
So let say I have w22qt4vhye1c
w99qt4vdf4vc
w22qt4vhzerct
geohash store in firebase and I want to query only which geohash close to w22qt4
.
How to do that?
I know firebase has startAt. I tried but not work.
UPDATE
Storing geohash to firebase
//Encode lat lng, result w22qt4vhye1c3
var geoHashLatLng = encodeGeoHash(lat,lng);
firebaseRef.child('/geohash/' + geoHashLatLng).set(id);
so in json
root
- geohash
- w22qt4vhye1c3
- id
- z99qt4vdf4vc
- w22qt4vhzerct
My question here.
I Just want to query geohash which start from characters w22qt4
. Can we do that in firebase?
UPDATE 2
startAt()
seems like not query with characters start with ...
Example: I have following gehash
geohash node
geohash
- a123
- a333
- b123
- c123
- d123
With the following code
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());
});
Will get this results
startAt(null, 'a') //return a123, a333, b123, c123, d123
startAt(null, 'c123') //return c123, d123
startAt(null, 'd') //return d123
My expected results
startAt(null, 'a') //return a123, a333
startAt(null, 'c123') //return c123
startAt(null, 'd') //return d123
My guess, startAt() will query the 26 alphabet letters in sequence but not matching. So, what can I do in firebase so I can get my expected results above?