根据距离在Firebase中搜索 [英] Search in Firebase based on distance

查看:59
本文介绍了根据距离在Firebase中搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在迁移一个使用Mysql到Firebase的应用程序,我设法迁移了几乎所有内容,只是缺少了搜索部分,我不太了解它是如何工作的.我正在尝试在Firebase中执行以下查询.

I'm migrating an application that was using Mysql to firebase, and I managed to migrate it almost all, just missing the part of search, I did not quite understand how it works. I'm trying to do this query below in firebase.

SELECT *, (6371 * acos( cos(radians(?)) * cos(radians(latitude)) * cos(radians(?) - radians(longitude)) + sin(radians(?)) * sin(radians(latitude)) )) AS distance FROM usuario ORDER BY distance

我想做的是将用户的纬度和经度传递给firebase,他让我从所有订购到最近的用户返回.

What I'm trying to do is pass the latitude and longitude of my User to firebase and he returns me all users ordering the nearest to the farthest.

注意:这与我在应用程序中使用的查询不同,我只是在google上找到该查询,但不知道这项工作是否可行,但是您可以了解我要执行的操作. 注意²:英语不是我的母语:P

Note: This is not the same query that I use in my application, that I just find on google and do not know if this work, but you can get an idea of what I'm trying to do. Note ²: English is not my native language :P

推荐答案

您提供的示例SQL查询使用了Firebase中不存在的SQL功能:该功能可以使用表,然后使用该表达式的值对查询结果进行过滤和排序.

The example SQL query you provided uses a capability of SQL that does not exist in Firebase: the ability to calculate an expression using the column values for each row in the table and then use the value of that expression to filter and sort the query result.

我看不到使用Firebase来执行所需查询类型的方法.

I don't see a way to use Firebase to perform the type of query you want.

您可能想看一下 Geofire库.我没有使用过它,它的功能似乎与邻近过滤有关,与您需要的按距离排序功能无关,但是也许您可以调整需求以利用它的功能.

You might want to take look at the Geofire library. I have not used it and its capabilities seem to be related to proximity filtering, not the sort-by-distance feature you need, but maybe you can adjust your requirements to make use of its features.

这篇关于根据距离在Firebase中搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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