Limit the number of queried items from GeoFire

后端 未结 2 543
南笙
南笙 2021-01-15 09:37

I have a lot of entry in the same location. I would like only to get the 10 latest added items using Geofire. I know that it can be done easily with firebase using Query.lim

相关标签:
2条回答
  • 2021-01-15 09:59

    There is no way to limit the number of keys from Geofire: it will return all keys that fall into the range you query for.

    The only thing I can think of is to not insert items if there is already another item in its vicinity. You're essentially clustering items while writing to the database in that case.

    0 讨论(0)
  • 2021-01-15 10:18

    There is only one solution for this :

    you should begin a query with a small radius,

    and each time you reach onGeoQueryReady() ("All data has been loaded"), you increase the radius by a small amount of the geoquery with .setRadius(r) until you reach the limit you want

    based on this https://github.com/firebase/geofire-js/issues/59

    0 讨论(0)
提交回复
热议问题