设置官方Google Maps for Flutter插件的说明包括将Google API密钥添加到AppDelegate.m文件中:
在应用程序委托ios / Runner / AppDelegate.m中指定您的API密钥:
#include "AppDelegate.h" #include "GeneratedPluginRegistrant.h" #import "GoogleMaps/GoogleMaps.h" @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [GMSServices provideAPIKey:@"YOUR KEY HERE"]; [GeneratedPluginRegistrant registerWithRegistry:self]; return [super application:application didFinishLaunchingWithOptions:launchOptions]; } @end
我的flutter项目有一个AppDelegate.swift文件而不是AppDelegate.m文件,我不知道如何添加所需的密钥,因为语法不同:
import UIKit import Flutter @UIApplicationMain @objc class AppDelegate: FlutterAppDelegate { override func application( _ application: UIApplication,didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]? ) -> Bool { GeneratedPluginRegistrant.register(with: self) return super.application(application,didFinishLaunchingWithOptions: launchOptions) } }
谁能帮我吗?
解决方法
您可以按如下方式添加API密钥:
AppDelegate.swift:
import UIKit import Flutter import GoogleMaps // Add this line! @UIApplicationMain @objc class AppDelegate: FlutterAppDelegate { override func application( _ application: UIApplication,didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]? ) -> Bool { GeneratedPluginRegistrant.register(with: self) GMSServices.provideAPIKey("YOUR_API_KEY") // Add this line! return super.application(application,didFinishLaunchingWithOptions: launchOptions) } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。