Reputation: 3064
I want to check if the user is in his/her house using their Geolocation. The app will be running in the foreground and no map will be displayed. The user's house lat and long will be stored in the Firestore.
When the user opens the app, I want to check whether he/she is in his house. As house size may vary, I would consider it for few meter of radius.
Any help will be appreciated.
Upvotes: 4
Views: 5180
Reputation: 445
There is an easy way:
MouseRegion(
onHover: (event) => setState(() {
Offset mousePosition = event.localPosition;
var circle = Path()..addOval(Rect.fromCircle(center: Offset(0, 0), radius: 50));
bool isHovered = circle.contains(mousePosition);
})
)
There are 2 things which you must set yourself: the Offset and the radius of the circle.
The Offset should be the middle of your child widget: width / 2 and height / 2. You can get this with LayoutBuilder if you don't have the size.
The radius can be width / 2.
Upvotes: -2
Reputation: 1800
You can do like this:
double getDistanceBetweenPositions({
required double homeLat,
required double homeLong,
required double userLat,
required double useLong,
}) {
final latDif = radians(homeLat - userLat);
final longDif = radians(homeLong - useLong);
final a = sin(latDif / 2) * sin(latDif / 2) +
cos(radians(userLat)) *
cos(radians(homeLat)) *
sin(longDif / 2) *
sin(longDif / 2);
final b = 2 * atan2(sqrt(a), sqrt(1 - a));
final result = earthRadius * b;
return result;
}
If the distance is <= the house size (your radius), it means user is in the house.
Upvotes: 0