Google maps 为什么使用最新的谷歌地图添加地图失败

Google maps 为什么使用最新的谷歌地图添加地图失败,google-maps,flutter,Google Maps,Flutter,我无法使用最新的pub版本将谷歌地图添加到我的flatter应用程序中 google_maps_flutter: ^0.5.28+1 错误:在类型为“GMSServices”的对象上找不到属性“ProvideAppKey” 您需要根据将API密钥包括在ios文件夹中 在swiftios/Runner/AppDelegate中。swift: import UIKit import Flutter import GoogleMaps @UIApplicationMain @objc c

我无法使用最新的pub版本将谷歌地图添加到我的flatter应用程序中

  google_maps_flutter: ^0.5.28+1
错误:在类型为“GMSServices”的对象上找不到属性“ProvideAppKey”

您需要根据将API密钥包括在ios文件夹中

在swift
ios/Runner/AppDelegate中。swift:

   import UIKit
import Flutter
import GoogleMaps

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GMSServices.provideAPIKey("YOUR KEY HERE")
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

  • (BOOL)provideAPIKey:(NSString*)APIKey
为Google Maps SDK for iOS提供API密钥

此密钥是通过谷歌云为您的应用程序生成的 平台控制台,并与应用程序的捆绑包ID配对以 识别它。您的应用程序必须准确调用此函数一次 在初始化任何iOS Maps SDK对象之前

返回: 如果成功提供了APIKey,则为“是”


在我的AppDelagte.m文件中,我输入了

[GMSServices.provideAPIKey@"MyApiKey"];
结果证明是错的。应该是

[GMSServices provideAPIKey:@"MyApiKey"];

我也遇到了这个错误,因为我忘记在AppDelegate.m iOS文件中包含GoogleMaps依赖项。请确保将其包含在导入的依赖项中:

#import "GoogleMaps/GoogleMaps.h"
这将是您的最终产品:

#include "AppDelegate.h"
#include "GeneratedPluginRegistrant.h"
#import "GoogleMaps/GoogleMaps.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  [GMSServices provideAPIKey:@"ABCDEFG123456789_v4"];
  [GeneratedPluginRegistrant registerWithRegistry:self];
  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
@end

您可以复制并粘贴它,只要用API密钥替换ABCDEFG123456789_v4即可~干杯

它已经在那里了!(我在错误文本中将其切换为“MyApiKey”,因为我不想与世界共享我的密钥。)因此这不是我的问题的原因。这更像是我的GMSServices版本没有属性provideAPIKey
[GMSServices.provideAPIKey@“MyApiKey”]这是错误的,我现在尝试使用
[GMSServices provideAPIKey:@“MyApiKey”]很高兴它能起作用。如果您能做标记作为答案,我们将不胜感激
#import "GoogleMaps/GoogleMaps.h"
#include "AppDelegate.h"
#include "GeneratedPluginRegistrant.h"
#import "GoogleMaps/GoogleMaps.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  [GMSServices provideAPIKey:@"ABCDEFG123456789_v4"];
  [GeneratedPluginRegistrant registerWithRegistry:self];
  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
@end