getLocationsConstraint function
Creates the necessary constraints to query for items in a FireStore collection that are inside a specific range from a center point
fieldName
: the name of the field in FireStore where the location of the items is stored
area
: Area within that the returned items should be
Implementation
List<QueryConstraint> getLocationsConstraint(String fieldName, Area area) {
// calculate the SW and NE corners of the bounding box to query for
final box = boundingBoxCoordinates(area);
// construct the GeoPoints
final lesserGeopoint = box.swCorner;
final greaterGeopoint = box.neCorner;
assert(box.swCorner.latitude < box.neCorner.latitude);
assert(box.swCorner.longitude < box.neCorner.longitude);
// print( "LOC: ${area.center.latitude}/${area.center.longitude}");
// print( "SW: ${box.swCorner.latitude}/${box.swCorner.longitude}");
// print( "NE: ${box.neCorner.latitude}/${box.neCorner.longitude}");
List<QueryConstraint> query = <QueryConstraint>[
new QueryConstraint(
field: fieldName,
isLessThan: greaterGeopoint,
),
new QueryConstraint(
field: fieldName,
isGreaterThan: lesserGeopoint,
)
];
return query;
}