You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

一加设备Flutter离线首次获取当前定位失败问题咨询

一加设备离线首次调用geolocator^9.0.2的getCurrentPosition()无返回且报GED_ERROR_FAIL错误

问题现象

一加设备在首次离线状态下调用getCurrentPosition()无结果返回,持续抛出系统日志:

E/GED (27929): ged_gpu_timestamp: GED_ERROR_FAIL eErr = 0, -2

  • 联网状态下定位功能正常
  • 离线二次调用可正常获取经纬度

解决方案

1. 强制指定离线定位模式

一加设备首次离线时,若默认位置模式为「高精度」(依赖网络),会导致定位服务卡住。调用getCurrentPosition前强制切换为仅设备模式,彻底脱离网络依赖:

import 'package:geolocator/geolocator.dart';

Future<Position?> getOfflinePosition() async {
  try {
    final position = await Geolocator.getCurrentPosition(
      locationSettings: LocationSettings(
        locationMode: LocationMode.deviceOnly, // 仅使用GPS/北斗等离线定位源
        accuracy: LocationAccuracy.medium,
        timeout: const Duration(seconds: 10), // 设置超时,避免无限等待
      ),
      forceAndroidLocationManager: true, // 强制使用Android原生定位管理器,绕过一加系统兼容问题
    );
    return position;
  } catch (e) {
    print("定位失败: $e");
    return null;
  }
}

2. 预加载定位服务(可选)

首次离线时一加的定位模块可能未完成初始化,可在APP启动阶段提前触发一次短超时的定位请求,完成模块预加载:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  
  // 预加载定位服务,忽略失败
  try {
    await Geolocator.getCurrentPosition(
      locationSettings: LocationSettings(
        locationMode: LocationMode.deviceOnly,
        timeout: const Duration(seconds: 5),
      ),
      forceAndroidLocationManager: true,
    );
  } catch (_) {}
  
  runApp(const MyApp());
}

3. GED_ERROR_FAIL日志说明

该日志是一加设备GPU驱动的错误输出,与定位功能本身无关,无需针对日志做额外处理,解决定位超时和模式问题后,定位无返回的现象会同步消除。

内容的提问来源于stack exchange,提问作者darshana vala

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 13:25:55