gpt4 book ai didi

How to query closest GeoPoints in a collection in Firebase Cloud Firestore?(如何在Firebase Cloud FiRestore中查询集合中最近的GeoPoint?)

转载 作者:bug小助手 更新时间:2023-10-25 11:24:07 28 4
gpt4 key购买 nike



The new Firestore DB allows me to store GeoPoints. Is there a way to query based on them?

新的FiRestore数据库允许我存储GeoPoints。有没有基于它们进行查询的方法?



So for example if each of my collections documents got a location field of the type geopoint.
How can I get the closest 10 documents to an arbitrary coordinate?

例如,如果我的每个集合文档都有一个geopoint类型的位置字段。如何才能获得最接近任意坐标的10个文档?



The documentation doesn't seem to cover this. I tried stuff like this:

文件似乎没有涵盖这一点。我试过这样的东西:



someRef.where('location', '>', geopoint).limit(10).get();


Obviously this doesn't make much sense but I'm just trying out some stuff here 😅

显然,这没有多大意义,但我只是在尝试一些东西,😅


更多回答
优秀答案推荐

We haven't exposed geoqueries yet, so currently there isn't a way to do this.

我们还没有公开地理查询,所以目前还没有办法做到这一点。



Historically, the Firebase Realtime Database used geohashes in a library called GeoFire--but given that we plan to expose actual geoqueries in the near future, we haven't updated that library to Firestore. To learn how to do something similar yourself though, have a look at this video.

在历史上,Firebase实时数据库使用名为GeoFire的库中的Geohash--但考虑到我们计划在不久的将来公开实际的地理查询,我们还没有将该库更新为FiRestore。想要学习如何做一些类似的事情,看看这个视频。



A new project has been introduced since @problemsofsumit first ask this question. The project is called GEOFirestore.

自从@ProblemsofSumit第一次提出这个问题以来,一个新的项目就被引入了。该项目名为GEOFiRestore。



With this library you can perform queries like query documents within a circle:

使用此库,您可以执行查询,就像在圆圈内查询文档一样:



  const geoQuery = geoFirestore.query({
center: new firebase.firestore.GeoPoint(10.38, 2.41),
radius: 10.5
});


You can install GeoFirestore via npm. You will have to install Firebase separately (because it is a peer dependency to GeoFirestore):

您可以通过NPM安装GeoFiRestore。您必须单独安装Firebase(因为它是GeoFiRestore的对等依赖项):



$ npm install geofirestore firebase --save


You can link to it via cdn:
https://cdn.jsdelivr.net/npm/[email protected]/dist/geofirestore.min.js

您可以通过cdn链接:https://cdn.jsdelivr.net/npm/[email(受保护)/dist/GeoFireStore.min.js



You could let Algolia do the geo search with radius for you. All it would require is to build a cloud function that triggers on your wanted documents and sync them to Algolia.

你可以让阿戈利亚为你做半径的地理搜索。它所需要的只是构建一个云功能,在你想要的文件上触发,并将它们同步到AlGolia。



Take a look at Geo Search https://www.algolia.com/doc/guides/searching/geo-search/

看看地理搜索https://www.algolia.com/doc/guides/searching/geo-search/



Also Firebase documentation advertises Algolia as a solution to complex searches here https://firebase.google.com/docs/firestore/solutions/search

此外,Firebase文档还宣传AlGolia是复杂搜索的解决方案,此处为https://firebase.google.com/docs/firestore/solutions/search



Rather than use third party services like Algolia I would use the new library that came out for both iOS and Android that replicates GeoFire for Firestore. The new library, called GeoFirestore, is fully documented and well tested. I have used this library already in many demo projects and it seems to work perfectly. Give it a shot!

我不会使用AlGolia等第三方服务,而会使用iOS和Android上推出的新库,它复制了GeoFire for FiRestore。新的库名为GeoFiRestore,有完整的文档记录,并经过了良好的测试。我已经在许多演示项目中使用过这个库,它似乎工作得很好。试一试吧!



After scouting the net, i found this GeoFirestore library by chintan369 that you could use to query nearby geopoints. The queries are based on Firestore native queries. Just add below line into your build.gradle (project-level):

在网上搜索后,我发现了Chintan369的这个GeoFiRestore库,你可以用它来查询附近的地理点。这些查询基于FiRestore原生查询。只需在您的build.gradle中添加以下行(项目级):



allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}


Then add the library to your build.gradle (app-level):

然后将库添加到你的build.gradle(APP级):



dependencies {
implementation 'com.github.chintan369:Geo-FireStore-Query:1.1.0'
}


...and sync your project.

...并同步您的项目。



Visit https://medium.com/android-kotlin/geo-firestore-query-with-native-query-bfb0ac1adf0a for more.

请访问https://medium.com/android-kotlin/geo-firestore-query-with-native-query-bfb0ac1adf0a了解更多信息。



A way of doing this may be adding 2 fields: one contain the GeoPoint + and the other the lat/lng converted to a single number, and after that performing queries with the last one

一种方法是添加两个字段:一个包含GeoPoint+,另一个包含转换为单个数字的LAT/LNG,然后使用最后一个执行查询


更多回答

Any idea how long before the geoqueries will be available? I am beginning development of an app that will rely on this functionality and I was about to use Realtime Database with GeoFire, but I would prefer to build the app with the new Firestore.

你知道地理查询要多久才能使用吗?我正在开始开发一个将依赖于此功能的应用程序,我即将使用GeoFire的实时数据库,但我更喜欢用新的FiRestore构建应用程序。

Am also waiting for this, or at least a simple compound query on multiple fields. Was really disappointed to see Uncaught Error: Invalid query. All where filters with an inequality (<, <=, >, or >=) must be on the same field. when trying out a query on lat and lng... This seems like the most basic functionality you'd expect even from a database in beta.

我也在等待这个,或者至少是一个简单的复合查询多个字段。看到未捕获的错误:无效查询真的很失望。所有带有不等式(<、<=、>或>=)的where过滤器必须位于同一字段上。当尝试查询纬度和纬度时...这似乎是您期望的最基本的功能,即使是测试版的数据库。

@Tequilaman is there a roadmap of upcoming features for FireStore? waiting on this one too and seriously considering implementing geohash search though if I can avoid it, i'd rather leave it to the experts :)

@Tequilaman是否有FireStore即将推出的功能路线图?也在等待这个问题,并认真考虑实现Geohash搜索尽管如果我可以避免它,我宁愿把它留给专家:)

geoqueries will be available?

地理查询是否可用?

Jan 2019. is it near yet ?

2019年1月。快到了吗?

can you elaborate on the installation for geoFirestore, im getting this error: stackoverflow.com/questions/51454724/…

您能详细说明GeoFiRestore的安装吗?我收到了这个错误:Stackoverflow.com/Questions/51454724/…

Het David, the geofirestore ra9r is referring to is different than the one in your comment. Mine is designed for JS, not iOS or Android (however I'd love to work with people who have ideas for those platforms as well!)

Het David,ra9r所指的GeoFirestore与您评论中的不同。我的设计是为JS设计的,而不是iOS或Android(不过,我也喜欢与那些对这些平台有想法的人合作!)

npm install geofirestore firebase --save is for firebase realtime database not firestore?

NPM安装GeoFirestore Firebase--保存用于Firebase实时数据库而不是FireStore?

$$$$$$$$$$$$$$$

$

I'm getting this error when installing via. cocoa pods did you get this error? stackoverflow.com/questions/51454724/…

安装VIA时出现此错误。可可豆,你收到这个错误了吗?STACKOVERFLOW.com/Questions/51454724/…

Cocoapods recently got updated. Since Imperium Labs has created a new release, you must run "pod repo update" and then "pod install" as the instructions say

CocoaPods最近进行了更新。由于Imperium Labs已经创建了一个新版本,因此您必须按照说明所述运行“Pod repo update”,然后运行“Pod Install

@NikhilSridhar is there any way to paginate the query in GeoFirestore, or atleast limit the results?

@NikHill Sridhar有没有办法在GeoFiRestore中对查询进行分页,或者至少限制结果?

Tried it. It does not work with big collections (>5k documents)

我试过了。它不适用于大集合(>5k文档)

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com