distance method
Calculates the distance between two GeoPoints.
Uses the geolocator package to calculate the distance in kilometers.
params
g1 and g2 are the two GeoPoints to calculate the distance between.
return
The distance in kilometers as an integer.
The distance is rounded to the nearest integer.
If the GeoPoints are null, an error is returned.
return
The distance in kilometers as an integer.
Implementation
int distance(GeoPoint g1, GeoPoint g2) {
return (Geolocator.distanceBetween(
g1.latitude,
g1.longitude,
g2.latitude,
g2.longitude,
) /
1000)
.round();
}