'How do I Query Firebase Firestore for a field of type Geopoint in Flutter?
I am querying a firestore collection for documents inside of a latitude and longitude range. Since it appears you can't conduct a query with arguments given to two different fields ('lat', 'lon'), I have assigned a type Geopoint to a single field 'coords' that has the longitude and latitude. How do I use .where() with geopoints? Below is the general query I would like to use, where _latMin, _latMax, etc. are variables linked to the bounding box of my map.
_getDocs() async {
print('getdocs');
final QuerySnapshot snapshot = await FirebaseFirestore.instance
.collection('collectionName')
.where(
'coords',
isGreaterThan: _latMin,
isLessThan: _latMax,
)
.where(
'coords',
isGreaterThan: _lonMin,
isLessThan: _lonMax,
)
.get();
snapshot.docs.forEach((DocumentSnapshot doc) {
print(doc.data());
});
}
How Do I reference the latitude and longitude inside of coords?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|


