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

Android模拟器中flutter_google_places搜索结果不显示的解决办法

Flutter Google Places 搜索无结果的模拟器解决办法

针对你遇到的搜索输入后无结果的问题,在模拟器环境下可以尝试以下排查和解决步骤:

  • 确认API密钥配置正确性

    1. 检查Google Cloud Console中,你的API密钥是否已启用Places API和Geocoding API,两者缺一可能导致搜索无结果。
    2. 若密钥设置了Android应用限制,务必将模拟器的调试SHA-1指纹添加到限制列表中。获取调试SHA-1的命令:
      # macOS/Linux
      keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
      # Windows
      keytool -list -v -keystore C:\Users\<你的用户名>\.android\debug.keystore -alias androiddebugkey -storepass android -keypass android
      
  • 调整搜索参数

    1. 当前设置strictbounds: true,若模拟器定位未开启或定位数据无效,严格边界会过滤掉所有结果。可先将该参数改为false测试,或在模拟器位置设置中手动指定美国境内的坐标。
    2. types: []的空数组配置可能在旧版本库中存在处理异常,尝试替换为具体类型如types: ["(cities)"]再测试。
  • 验证网络与权限

    1. 确认模拟器可正常访问外网,可通过模拟器内置浏览器测试Google服务的连通性。
    2. 检查AndroidManifest.xml中是否添加了网络权限:
      <uses-permission android:name="android.permission.INTERNET"/>
      
  • 排查API请求状态

    1. 登录Google Cloud Console,进入API和服务→仪表盘,查看Places API的请求日志,确认是否存在请求被拒绝、权限不足等错误提示。
    2. 在代码中添加异常捕获,打印请求相关信息:
      try {
        Prediction? p = await PlacesAutocomplete.show(
          context: context,
          radius: 10000000,
          types: [],
          strictbounds: true,
          mode: Mode.overlay,
          language: "en",
          components: [Component(Component.country, "US")],
          apiKey: kGoogleApiKey);
        print("搜索结果: $p");
      } catch (e) {
        print("请求异常: $e");
      }
      
  • 检查版本兼容性
    flutter_google_places 0.3.0版本较旧,可能存在与新版Flutter SDK的兼容性问题,建议升级到最新稳定版本后重试。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 13:47:17