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

Flutter应用中Google Maps无法显示但API调用成功的排查求助

集成Google Maps的Flutter应用地图空白问题求助

我正在开发集成Google Maps的Flutter应用,尽管Google Cloud Platform控制台显示API调用成功,但地图始终无法显示。

以下是我已完成的排查操作:

  • 确认API密钥已正确配置在AndroidManifest.xml中
  • 在AndroidManifest.xml中设置了位置和网络权限
  • 在模拟器上测试应用
  • 确保API密钥已在Google Cloud Platform对应项目中激活且无限制
  • 已升级至最新版Flutter及google_maps_flutter插件

以下是我的Dart核心代码片段:

class CirclesPage extends StatefulWidget {
  const CirclesPage({Key? key}) : super(key: key);

  @override
  _CirclesPageState createState() => _CirclesPageState();
}

class _CirclesPageState extends State<CirclesPage> {
  GoogleMapController? _controller;
  LatLng currentLocation = LatLng(46.8182, 8.2275); // Default to Switzerland

  @override
  void initState() {
    super.initState();
    _determinePosition().then((_) => _goToCurrentLocation());
  }

  void _onMapCreated(GoogleMapController controller) {
    _controller = controller;
    _goToCurrentLocation();
  }

  Future<void> _goToCurrentLocation() async {
    if (_controller == null) return;
    _controller!.animateCamera(CameraUpdate.newLatLngZoom(currentLocation, 15.0));
  }

  Future<void> _determinePosition() async {
    // Location service check and permission handling logic
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Maps Sample')),
      body: GoogleMap(
        onMapCreated: _onMapCreated,
        myLocationEnabled: true,
        initialCameraPosition: CameraPosition(
          target: currentLocation,
          zoom: 15.0,
        ),
      ),
    );
  }
}

日志显示initState、onMapCreated和build函数均已调用,但地图区域仍为空白。求各位指点遗漏点或下一步排查方向。

更新1:我怀疑是SHA-1密钥配置错误,正在处理,必要时会删除此问题。
更新2:重新配置SHA-1密钥后问题仍未解决,仅在执行以下终端命令后调用页面时,地图才能正常请求并显示:

flutter clean
flutter pub get

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.27 12:12:43