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

启动Expo应用时出现‘Geocoder is not running’错误的咨询

Expo Android APK 调用 reverseGeocodeAsync 报错「Geocoder is not running」的解决办法

问题现象

通过eas build打包的Android APK安装到真机后,授予位置权限调用ExpoLocation.reverseGeocodeAsync()时,几秒后抛出Geocoder is not running错误;但用Expo Go运行完全正常。已尝试移除android.permissions配置,问题依旧。使用Expo SDK 46,在App.js启动阶段调用getCurrentLocation函数。

相关配置与代码

app.json 配置

{"expo": {"name": "***","scheme": "***","slug": "***","version": "1.0.0","orientation": "portrait","icon": "./assets/icon.png","userInterfaceStyle": "automatic","splash": {"image": "./assets/splash.png","resizeMode": "contain","backgroundColor": "#ffffff"},"assetBundlePatterns": ["**/*"],"ios": {"supportsTablet": true},"android": {"adaptiveIcon": {"foregroundImage": "./assets/adaptive-icon.png","backgroundColor": "#FFFFFF"},"softwareKeyboardLayoutMode": "pan","package": "com.***.***","permissions": ["ACCESS_COARSE_LOCATION","ACCESS_FINE_LOCATION"]},"androidNavigationBar": {"barStyle": "dark-content"},"androidStatusBar": {"barStyle": "dark-content"},"web": {"favicon": "./assets/favicon.png"},"updates": {"enabled": false},"extra": {"eas": {"projectId": "***"}}}}

位置获取函数

import * as ExpoLocation from 'expo-location';

export const getCurrentLocation = async () => {
  let { status } = await ExpoLocation.requestForegroundPermissionsAsync();

  if (status === 'granted') {
    let location = await ExpoLocation.getCurrentPositionAsync({
      accuracy: ExpoLocation.LocationAccuracy.Low,
    });

    let address = await ExpoLocation.reverseGeocodeAsync({
      latitude: location.coords.latitude,
      longitude: location.coords.longitude,
    });

    return address[0].city;
  } else {
    return null;
  }
};

可行解决方案

  • 添加后台位置权限:在app.json的android.permissions中加入ACCESS_BACKGROUND_LOCATION。部分Android设备的地理编码服务依赖该权限才能正常初始化,即使你只用到前台定位。修改后配置如下:

    "android": {
      // ...其他原有配置
      "permissions": [
        "ACCESS_COARSE_LOCATION",
        "ACCESS_FINE_LOCATION",
        "ACCESS_BACKGROUND_LOCATION"
      ]
    }
    
  • 延迟地理编码调用:避免在App启动瞬间调用reverseGeocodeAsync,给系统地理编码服务留足初始化时间。可以在启动逻辑中加入1秒左右的延迟:

    // 在App组件的useEffect中调用
    useEffect(() => {
      const initLocation = async () => {
        await new Promise(resolve => setTimeout(resolve, 1000));
        const city = await getCurrentLocation();
        // 处理获取到的城市信息
      };
      initLocation();
    }, []);
    
  • 调整expo-location版本:SDK 46对应的expo-location部分版本存在该bug,尝试切换到14.4.0(SDK 46支持的稳定版本):

    npm install expo-location@14.4.0
    # 或 yarn add expo-location@14.4.0
    
  • 检查设备系统服务:部分设备可能禁用了地理编码相关系统服务,前往设备设置→应用管理→找到「Google服务框架」或「位置服务」,确保服务处于启用状态且权限正常。

内容的提问来源于stack exchange,提问作者2PB

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.28 14:32:18