Google Maps for Flutter iOS Swift setup
4,234
Solution 1
You can add your API key as follows:
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)
}
}
Solution 2
One more thing, Dont forget to add below line on ios/Runner/Info.plist
<key>io.flutter.embedded_views_preview</key>
<true/>
Author by
Kretin
Updated on December 08, 2022Comments
-
Kretin over 1 year
The instructions for setting up the official Google Maps for Flutter plugin include adding the Google API key to the AppDelegate.m file:
Specify your API key in the application delegate ios/Runner/AppDelegate.m:
#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
My flutter project has an AppDelegate.swift file instead of an AppDelegate.m file and I'm not sure how to add the required key, as the syntax is different:
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) } }
Can anyone help me out?