flutter-geolocator
flutter-geolocator copied to clipboard
[Question]: i am trying to call _storeAttendance(action); based on distance but however the distance is wrong even though the location is same
Please check the following before submitting a new issue.
- [X] I have searched the existing issues.
- [X] I have carefully read the documentation.
Please select for which platform(s) you need help
- [X] Android
- [ ] iOS
- [ ] Linux
- [ ] macOS
- [ ] Web
- [ ] Windows
Your question
Future<void> getCurrentPos(String action) async {
currentPos = await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.medium);
print("latitude: ${currentPos.latitude} , target latitude : ${targetLatitude}");
print("longitude: ${currentPos.longitude}, target longitude : ${targetLongitude}");
double distance = Geolocator.distanceBetween(
currentPos.latitude,
currentPos.longitude,
targetLatitude,
targetLongitude,
);
print("the distance is ${distance}");
if (distance <= 100) {
await _storeAttendance(action);
} else {
_showResultDialog("Failed", "You are not within the required distance to check in/out.");
}
}
here is the console prints :
I/flutter (13227): latitude: 20.9931481 , target latitude : 20.9911605 I/flutter (13227): longitude: 75.5525976, target longitude : 75.5515482 I/flutter (13227): the distance is 246.6792033217311
Version
12.0.0