首页 > 解决方案 > GetCurrentLocation 在调试中工作,但在 Android 的发布 apk 中不起作用

问题描述

我遇到了 geolocator 包的问题,​​当我在调试模式下运行我的应用程序时,一切正常,但是当我构建应用程序并使用发布模式时,它卡在了我的加载屏幕中,其中有来自 geolocator 包的 getcurrentlocation。

Future<void> getCurrentLocation() async {
    try {
      Geolocator geolocator = Geolocator()..forceAndroidLocationManager = true;
      Position position = await geolocator.getCurrentPosition(
        desiredAccuracy: LocationAccuracy.low,
      );
      latitude = position.latitude;
      longitude = position.longitude;
    } catch (e) {
      print(e);
    }
  }

并添加到 android 清单访问。

标签: androidflutterdartpluginsgeolocation

解决方案


对于我的情况,我发现我必须在 AndroidManifest 中添加互联网权限。xml

<uses-permission android:name="android.permission.INTERNET" />

推荐阅读