简体   繁体   中英

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.

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.

the problem is that the only library I know is geofire,

As far as I know is the only one for the moment.

If I query on a certain radius (10 km)

This is possible for sure.

than I need to query from 10km to 20km I can't

You cannot query but you can get the locations from 10km to 20km, which I think is what you want. 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.

which means I query (and pay) first 10km for nothing because I already had them.

No, you don't pay for those location that are within 10 km since those locations are coming from cache. So when you perform the second query (from 10km to 20km) you'll be charged only for the locations within that range.

The problem comes if you want to get the locations from 10km to 20km directly without having the locations from 0km to 10km. In that case, you get all locations from 0km to 20km, and then perform another query to get all locations from 0km to 10km. Now, to have all location from 10km to 20km, simply remove all locations that you get from the second query. So in both cases, you need to perform two queries.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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