How to query Firebase for keys that match a string prefix

后端 未结 2 1492
梦谈多话
梦谈多话 2021-02-04 15:20

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 w2

2条回答
  •  梦谈多话
    2021-02-04 16:15

    You can use a normal startAt query to find keys near the specified key. For example, in this case you'd:

    var query = firebaseRef.child("geohash").startAt(null, 'c').limit(5);
    query.on("child_added", ...);
    

    This will give you the 5 elements after geoHashLatLng when sorted lexigraphically.

    If you want to end your query at some specified key, you can do that as well. For example:

    var query = firebaseRef.child("geohash").startAt(null, 'c').endAt('d');
    

提交回复
热议问题