简体   繁体   English

有没有一种简单有效的方法来查询 Firebase 上的地理点?

[英]Is there an easy and efficient way to query geopoints on Firebase?

I'm currently developing a Flutter app based on geolocation, I need to query based on a variable radius.我目前正在开发基于地理位置的 Flutter 应用程序,我需要根据可变半径进行查询。

Every document in my database has a field named "position" with a geohas and a geopoint, the problem is that the only library I know is geofire, but this is not really efficient, because If I query on a certain radius (10 km) and than I need to query from 10km to 20km I can't: I can just query again with a fixed 20km radius, which means I query (and pay) first 10km for nothing because I already had them.我数据库中的每个文档都有一个名为“position”的字段,其中包含 geohas 和 geopoint,问题是我知道的唯一库是 geofire,但这并不是很有效,因为如果我查询某个半径(10 公里)而不是我需要从 10 公里查询到 20 公里,我不能:我可以用固定的 20 公里半径再次查询,这意味着我查询(并支付)前 10 公里是免费的,因为我已经有了它们。

the problem is that the only library I know is geofire,问题是我知道的唯一图书馆是geofire,

As far as I know is the only one for the moment.据我所知是目前唯一的一个。

If I query on a certain radius (10 km)如果我查询某个半径(10 公里)

This is possible for sure.这肯定是可能的。

than I need to query from 10km to 20km I can't比我需要从 10km 查询到 20km 我不能

You cannot query but you can get the locations from 10km to 20km, which I think is what you want.您无法查询,但您可以获得 10 公里到 20 公里的位置,我认为这是您想要的。 Since you already have the locations within 10km, when you query the locations from 0km to 20km, every location that you get is new, which means that is located from 10km to 20km.由于你已经有了 10km 内的位置,所以当你查询 0km 到 20km 的位置时,你得到的每个位置都是新的,即位于 10km 到 20km 之间。

which means I query (and pay) first 10km for nothing because I already had them.这意味着我免费查询(并支付)前 10 公里,因为我已经拥有它们。

No, you don't pay for those location that are within 10 km since those locations are coming from cache.不,您无需为 10 公里以内的位置付费,因为这些位置来自缓存。 So when you perform the second query (from 10km to 20km) you'll be charged only for the locations within that range.因此,当您执行第二次查询(从 10 公里到 20 公里)时,您只需为该范围内的位置付费。

The problem comes if you want to get the locations from 10km to 20km directly without having the locations from 0km to 10km.如果您想直接获取 10 公里到 20 公里的位置,而不需要 0 公里到 10 公里的位置,就会出现问题。 In that case, you get all locations from 0km to 20km, and then perform another query to get all locations from 0km to 10km.在这种情况下,您获取 0km 到 20km 的所有位置,然后执行另一个查询以获取 0km 到 10km 的所有位置。 Now, to have all location from 10km to 20km, simply remove all locations that you get from the second query.现在,要获得从 10 公里到 20 公里的所有位置,只需删除从第二个查询中获得的所有位置。 So in both cases, you need to perform two queries.因此,在这两种情况下,您都需要执行两个查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM