加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

适用于Flutter iOS设置的Google Maps

发布时间:2020-12-14 14:52:29 所属栏目:百科 来源:网络整理
导读:设置官方Google Maps for Flutter插件的说明包括将Google API密钥添加到AppDelegate.m文件中: 在应用程序委托ios / Runner / AppDelegate.m中指定您的API密钥: #include "AppDelegate.h" #include "GeneratedPluginRegistrant.h"#import "GoogleMaps/Googl
设置官方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)
  }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读