0

What I'm trying to do:

I have a collection called "Users" where each user(document) has its own latitude and longitude saved inside of that file. With that, I'm trying to do a query which will look something like this.

_firestore
        .collection('Users')
        .where('lat', isGreaterThanOrEqualTo: docLat)
        .where('lat', isLessThanOrEqualTo: maxLat)
        .where('lon', isGreaterThanOrEqualTo: docLon)
        .where('lon', isLessThanOrEqualTo: maxLon)

Error:

PlatformException (PlatformException(error, All where filters other than whereEqualTo() must be on the same field. But you have filters on 'lat' and 'lon', null))


Problems:

  1. I can not use GeoPoint as type in my document. Why? Because if I will search base on that, something like this:

_firestore .collection('Users') .where('geopoint', isGreaterThanOrEqualTo: myGeopoint) .where('geopoint', isLessThanOrEqualTo: limitGeopoint)

is not going to work because it will comper just the Latitude of my GeoPoint, and the Longitude is going to be ignored.

  1. I can not use Geohash. If will compare them in the same way as I did with GeoPoints it will fail to show me all the results because the way how geohash works.

  2. I know about some packages like firestore_helpers or geoflutterfire. But the problem with those is that I CAN NOT limit the result set. I etcher get all of them or not. Or if have any idea how can I limit them let me know (no, I don't want to limit the collection result, before the data is going to be sent to one of those packages, check my last question)


What I've tried to do:

I head about Composite Index used in firebase and I've made them like this. enter image description here

But the query is still not working and I wasn't able to find any example with composite index yet used in flutter (or at least dart) for my case.

So far as I understood I need to use the Compose Index something like this.

 _firestore
        .collection('Users')
        .where('lat_lon', isGreaterThanOrEqualTo: userData.geopoint.latitude.toString() + "_0.0")
        .where('lat_lon', isLessThanOrEqualTo: maxLimit.latitude.toString() + "_0.0")
        .where('lat_lon', isGreaterThanOrEqualTo:  "0.0_" + userData.geopoint.longitude.toString())
        .where('lat_lon', isLessThanOrEqualTo: "0.0_" +maxLimit.longitude.toString())

But is not working either. Do you have any solution for me? I really need to find a way to fix this.

Mircea
  • 1,671
  • 7
  • 25
  • 41

0 Answers0