DarshanGowda0 / GeoFlutterFire

:fire:GeoFlutterFire:fire: is an open-source library that allows you to store and query firestore documents based on their geographic location.
https://youtu.be/MYHVyl-juUk
MIT License
305 stars 261 forks source link

Query don't works with where #99

Closed s3bok closed 3 years ago

s3bok commented 4 years ago

I need to do a query, first I tried with group by and after with Where, I did a index in FireStore, but the query return all matches with position... (i read the issues here, but the last was since one year) With startAt

 var collectionReference = _firestore.collection('products').orderBy('nameFilter').startAt(listValue).endAt(listValue+ '\uf8ff');
    geo.collection(collectionRef: collectionReference.reference())
    .within(center: pointUser, radius: distance, field: 'companyPosition', strictMode: true);

With Where

 var collectionReference = _firestore.collection('products').where('nameFilter', isEqualTo: listValue);
    geo.collection(collectionRef: collectionReference.reference())
    .within(center: pointUser, radius: distance, field: 'companyPosition', strictMode: true);

I have the Inex in FireStore image

guptasulabh commented 4 years ago

Even i m facing same issue. GeoFlutterFire works perfectly with location/nearby results but as soon as where condition is added, it stops working.

Stijnp commented 4 years ago

Second that, hoping someone here has a fix as this otherwise would be quite wasteful calculating all distances to then remove 70% of the results after being loaded.

s3bok commented 4 years ago

I decided don't to use the library and I do a query with Geohash, you can use this reference https://www.movable-type.co.uk/scripts/geohash.html

First with Firestore I have the geopoint with geohash, so I do a query using start at "gbsuv", the results depends of Geohash length, like can you see in the web page, for example I use 5 characters that returns alls around 4.89km.

And I cant use where clause, whitout forget create the index in Firestore.

Sorry for my English friends.

guptasulabh commented 4 years ago

I decided don't to use the library and I do a query with Geohash, you can use this reference https://www.movable-type.co.uk/scripts/geohash.html

First with Firestore I have the geopoint with geohash, so I do a query using start at "gbsuv", the results depends of Geohash length, like can you see in the web page, for example I use 5 characters that returns alls around 4.89km.

And I cant use where clause, whitout forget create the index in Firestore.

Sorry for my English friends.

Yes, even i m not using this library now. But can you please tell how to use start at with a String saved having geoHash?

s3bok commented 4 years ago

Yes, even i m not using this library now. But can you please tell how to use start at with a String saved having geoHash?

I'm doing with geohash in firebase. image

This is my query, I'm using where for filters, that for me is more easy use an array and an index

db.collection('company').orderBy('companyPosition.geohash').startAt('gbsuv').endAt('gbsuv' + '\uf8ff') .where('filters', 'array-contains-any', ['My_Company','Type']).get().then(res => {...

ndhbr commented 4 years ago

So it is not possible to add a where condition? I got a link to create the index, but that didn't help either...

israelpazlop commented 4 years ago

So it is not possible to add a where condition? I got a link to create the index, but that didn't help either...

I tried to add a where condition with index but for me that was imposible... so i done the query with geohash and for now it works, for me it's ok because I'm going to change the database after if is necesary

janlektonen commented 4 years ago

I can confirm that .where is not working. I've tried many things but i get null return when adding .where to my collectionreference... I have created index ect... I can also see that the code for this is outcommented in the Flutter/dart package example, so developer must be aware of the problem.

I would really much like to use query with .where - any plan on solving this issue soon ?

Thanks for a great package! /Jan

s3bok commented 4 years ago

I can confirm that .where is not working. I've tried many things but i get null return when adding .where to my collectionreference... I have created index ect... I can also see that the code for this is outcommented in the Flutter/dart package example, so developer must be aware of the problem.

I would really much like to use query with .where - any plan on solving this issue soon ?

Did you try with geohash ? I did some queries with where and it works fine... can you share your query example to see if I can helpyou ?

janlektonen commented 4 years ago

Hi @s3bok I've updated to new Flutter 1.20.2 and also Firebase Core 0.5.0 and now it is working when I include .where in the collection 👍 I could be that my index in firestore was wrong as I also created a new for the query, but anyway, thanks for helping.

s3bok commented 4 years ago

Hi @s3bok I've updated to new Flutter 1.20.2 and also Firebase Core 0.5.0 and now it is working when I include .where in the collection 👍 I could be that my index in firestore was wrong as I also created a new for the query, but anyway, thanks for helping.

Excellent, I'm goint to try that.

jesusrb89 commented 4 years ago

I need a query that includes an order by date and by geolocation, is this possible? someone help me? Thx!

s3bok commented 4 years ago

I need a query that includes an order by date and by geolocation, is this possible? someone help me? Thx!

If you are using the library, I believe that it orders by position you need test that... about order by date you can use in your collection the order by:

Firestore.instance
     .collection('YOUR-COllection')
     .orderBy('createdAt', descending: true or false).getDocuments()

However, I decided not use le library and create the query using geoHash, if you need help you can share your query...

sorry the English isn't my first language, I'm from Mexico

SdxCoder commented 3 years ago

I faced the same issue, but nothing is wrong with library, just add composite index to firestore,like position.geohash in ascending order , because it orders by geohash here in this function of library.

 /// construct a query for the [geoHash] and [field]
  Query _queryPoint(String geoHash, String field) {
    final end = '$geoHash~';
    final temp = _collectionReference;
    return temp.orderBy('$field.geohash').startAt([geoHash]).endAt([end]);
  }
Bader-Al commented 3 years ago

Wrapping the entire thing in try catch worked for me (print the error and you'll get the link to build the index automatically )

saulvh commented 3 years ago

You need to add the index in firebase for it to work, you can add the .onError validation in the streambuilder and get the link to make the index automatically.

naveenbharadwaj19 commented 3 years ago

Yes, even i m not using this library now. But can you please tell how to use start at with a String saved having geoHash?

I'm doing with geohash in firebase. image

This is my query, I'm using where for filters, that for me is more easy use an array and an index

db.collection('company').orderBy('companyPosition.geohash').startAt('gbsuv').endAt('gbsuv' + '\uf8ff') .where('filters', 'array-contains-any', ['My_Company','Type']).get().then(res => {...

I'm having a document where i store users age , name , location (lat,long,geohash). What i want is find whether they are within in the radius is it possible ? and i need to show next set of user details (paginate) when user scroll @s3bok

awaik commented 3 years ago

Solved https://github.com/DarshanGowda0/GeoFlutterFire/issues/99#issuecomment-654582093