flutter-geolocator icon indicating copy to clipboard operation
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

Open devlprRohit opened this issue 1 year ago • 2 comments

Please check the following before submitting a new issue.

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

devlprRohit avatar Aug 13 '24 06:08 devlprRohit