Flutter应用集成Google Maps后iOS端无法显示问题求助
排查步骤
- 检查iOS端API密钥配置
打开ios/Runner/AppDelegate.swift文件,确认已在入口方法中正确初始化Google Maps服务:
若使用Objective-C版本的AppDelegate,对应添加import UIKit import Flutter import GoogleMaps // 确认导入该库 @UIApplicationMain @objc class AppDelegate: FlutterAppDelegate { override func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { GMSServices.provideAPIKey("你的Google Maps iOS API密钥") // 确认该行存在且密钥正确 GeneratedPluginRegistrant.register(with: self) return super.application(application, didFinishLaunchingWithOptions: launchOptions) } }#import <GoogleMaps/GoogleMaps.h>和[GMSServices provideAPIKey:@"你的API密钥"];即可。 - 清理缓存重新拉取依赖
依次执行以下命令重置iOS端依赖:# 项目根目录执行 flutter clean rm -rf ios/Pods ios/Podfile.lock # 进入ios目录执行 cd ios pod deintegrate pod update GoogleMaps # 回到根目录重新运行 cd .. flutter run - 校验Info.plist配置
除io.flutter.embedded_views_preview设置为true外,若你的地图功能用到定位能力,需确认已添加对应权限说明:NSLocationWhenInUseUsageDescription:App使用期间的定位权限说明NSLocationAlwaysAndWhenInUseUsageDescription:后台定位权限说明(按需添加)
- 核对Google Cloud API密钥配置
确认你使用的iOS端API密钥没有配置错误的Bundle ID限制,同时确认Maps SDK for iOS的配额没有耗尽,可直接打开Xcode运行项目查看控制台输出,Google Maps SDK会直接输出加载失败的具体原因(如密钥无效、权限未开启等)。 - 校验包版本兼容性
确认pubspec.yaml中google_maps_flutter依赖版本不低于2.0.6,该版本开始适配Flutter 2.x及空安全规范,避免低版本和高版本Flutter不兼容导致加载异常。
内容的提问来源于stack exchange,提问作者Whezer
相关产品推荐
相关产品推荐

