flutter-geolocator icon indicating copy to clipboard operation
flutter-geolocator copied to clipboard

getCurrentPosition on Android12 and some Huawei models report an error TimeoutException

Open armomu opened this issue 3 years ago • 5 comments

🐛 Bug Report

The "getCurrentPosition" method is normal for models below Android 12. Android 12 and some Huawei models report an error "TimeoutException after 0:00:03.000000: Future not completed", but the "getLastKnownPosition" method is normal.

Expected behavior

I/flutter (15995): 获取当前位置出错===TimeoutException after 0:00:03.000000: Future not completed

Reproduction steps

 try {
      ....
      LocationPermission permission = await Geolocator.checkPermission();
      permission = await Geolocator.checkPermission();
      if (permission == LocationPermission.denied ||
          permission == LocationPermission.deniedForever) {
        EasyLoading.showToast('定位失败!请确认授权或开启手机定位');
        throw null;
      }
      Position _currentPosition;
      _currentPosition = await Geolocator.getCurrentPosition(
          desiredAccuracy: LocationAccuracy.medium,
          timeLimit: Duration(seconds: Platform.isIOS ? 5 : 3),
          forceAndroidLocationManager: true);
      ....
    } catch (e) {
      print('获取当前位置出错===$e');
      return catchErr();
    }

Configuration

Version: 8.2.0

Platform:

  • [ ] :iphone: iOS
  • [x] :robot: Android12

armomu avatar Mar 18 '22 04:03 armomu

same error The problem only appears when the forceAndroidLocationManager is true

Flutter 2.10.3 Geolocator 8.2.0

mhdkadi avatar Apr 09 '22 09:04 mhdkadi

Possibly related to #1027 and #1114.

Zverik avatar Aug 09 '22 09:08 Zverik

same error The problem only appears when the LocationAccuracy.medium Only a few phones won't get the location It has nothing to do with #1027 or #1114

AnAnyy avatar Aug 21 '23 07:08 AnAnyy

Same error here as well.

Until a few updates ago, it was working fine but now it doesn't.

And I am not using forceAndroidLocationManager and the precise location is not off.

i have tried using time-limit finally to limit the call otherwise the getCurrentPosition keeps on checking.

    Position position;
    String latitude = '';
    String longitude = '';
    try {
      position = await Geolocator.getCurrentPosition(
        desiredAccuracy: LocationAccuracy.best,
        timeLimit: Duration(seconds: 30),
      );
      latitude = position.latitude.toStringAsFixed(3);
      longitude = position.longitude.toStringAsFixed(3);
    } catch (e) {
      logger.e(e);
      return ToastMessage.showEmptyPlaceToast();
    }

My device specs: Android 13 both on real device and emulator

milindgoel15 avatar Sep 11 '23 07:09 milindgoel15