How find nearest users by latitude and longitude?

前端 未结 1 1505
你的背包
你的背包 2020-12-22 09:16

I\'m using firebase I\'m thinking the way how to do this.

  1. get all user\'s latitude and logitude and save it to firebaseDB
  2. sorting nearest users to me
相关标签:
1条回答
  • 2020-12-22 09:29

    You're on the right track. But there is no API to find the nearest user.

    There is however an add-on library called GeoFire that allows you to find all keys within a certain range. It does this by encoding the user location in a so-called geohash, which it then allows you to query.

    With this you could:

    1. take a reasonable range
    2. get all keys in that range through a geoquery
    3. pick the closest key
    4. if no key was found, expand the range
    0 讨论(0)
提交回复
热议问题