如何通过纬度和经度找到最近的用户? [英] How find nearest users by latitude and longitude?

查看:86
本文介绍了如何通过纬度和经度找到最近的用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Firebase 我在想如何做到这一点.

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

  1. 获取所有用户的纬度和经度并将其保存到firebaseDB
  2. 在firebaseDB中排序距离我最近的用户
  3. 获取数据并显示最近的用户

但是我在文档的db中找不到源代码 有什么办法可以在firebaseDB中对我附近的用户进行排序? 或其他方式?

But I couldn't find sotring in db in document Is there a way I can sort nearest users to me in firebaseDB? or other ways?

推荐答案

您处在正确的轨道上.但是没有API可以找到最近的用户.

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

但是,有一个名为 GeoFire 的附加库,您可以在其中找到所有密钥一定范围.它通过将用户位置编码为所谓的geohash来实现,然后允许您查询.

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.

有了这个,您可以:

  1. 保持合理范围
  2. 通过地理查询获取该范围内的所有键
  3. 选择最接近的键
  4. 如果未找到密钥,请扩大范围

这篇关于如何通过纬度和经度找到最近的用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆