Flutter Google Maps 教程
设置
-
在 https://cloud.google.com/maps-platform/ 获取 API 密钥
-
启用 Maps SDK for Android、Maps SDK for iOS 和 Directions API。
-
将您的 API 密钥添加到指定的文件
android/app/src/main/AndroidManifest.xml
<manifest ...
<application ...
<meta-data android:name="com.google.android.geo.API_KEY"
android:value="YOUR KEY HERE"/>
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)
}
}
lib/.env.dart
const String googleAPIKey = 'YOUR KEY HERE';