firestore_helpers library
Classes
-
Area
-
Defines the search area by a circle center / radius
Based on the limitations of FireStore we can only search in rectangles
which means that from this definition a final search square is calculated
that contains the circle
-
GeoBoundingBox
-
Defines the boundingbox for the query based
on its south-west and north-east corners
-
OrderConstraint
-
Used by buildQuery to define how the results should be ordered. The fields
corespond to the possisble parameters of Firestore`s
oderby()
method.
-
QueryConstraint
-
Used by buildQuery to define a list of constraints. Important besides the field property not more than one of the others can ne
!=null
.
They corespond to the possisble parameters of Firestore`s where()
method.
Functions
-
boundingBoxCoordinates(Area area)
→ GeoBoundingBox
-
Calculates the SW and NE corners of a bounding box around a center point for a given radius;
area
with the center given as .latitude and .longitude
and the radius of the box (in kilometers)
-
buildQuery({CollectionReference collection, List<QueryConstraint> constraints, List<OrderConstraint> orderBy })
→ Query
-
Builds a query dynamically based on a list of QueryConstraint and orders the result based on a list of OrderConstraint.
collection
: the source collection for the new query
constraints
: a list of constraints that should be applied to the collection
.
orderBy
: a list of order constraints that should be applied to the collection
after the filtering by constraints
was done.
Important all limitation of FireStore apply for this method two on how you can query fields in collections and order them.
-
degreesToRadians(double degrees)
→ double
-
-
distance(GeoPoint location1, GeoPoint location2)
→ double
-
Calculates the distance, in kilometers, between two locations, via the
Haversine formula. Note that this is approximate due to the fact that
the Earth's radius varies between 6356.752 km and 6378.137 km.
location1
The first location given
location2
The second location given
sreturn the distance, in kilometers, between the two locations.
-
getData<T>(Query query, DocumentMapper<T> mapper)
→ Stream<List<T>>
-
Convenience Method to access the data of a Query as a stream while applying a mapping function on each document
qery
: the data source
mapper
: mapping function that gets applied to every document in the query.
-
getLocationsConstraint(String fieldName, Area area)
→ List<QueryConstraint>
-
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
-
metersToLongitudeDegrees(double distance, double latitude)
→ double
-
Calculates the number of degrees a given distance is at a given latitude.
distance
The distance to convert.
latitude
The latitude at which to calculate.
returns the number of degrees the distance corresponds to.
-
wrapLongitude(double longitude)
→ double
-
Wraps the longitude to
-180,180
. [...]