在Swift中将GMSMapView分配给UIView

ISH*_*HAN 4 google-maps swift

我创建了这两个变量

var googleMap = GMSMapView()

@IBOutlet weak var mapView: UIView!
Run Code Online (Sandbox Code Playgroud)

我在viewDidLoad()中将googleMap指定给mapView

    override func viewDidLoad() {
        super.viewDidLoad()
        self.mapView = self.googleMap //Throwing error as 'Google Maps SDK for iOS must be initialized via [GMSServices provideAPIKey:...] prior to use'
}
Run Code Online (Sandbox Code Playgroud)

我在AppDelegate.swift中提供密钥

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.
    GMSServices.provideAPIKey("AIzaSyB6aQxEmza-wUpOPU60aREWReRIAEAvrHs")
    return true
}
Run Code Online (Sandbox Code Playgroud)

任何人都可以指出我解决这个问题的方向吗?

LuK*_*eth 7

您不会以这种方式将GMSMapView分配给您的UIView.这是你如何做到的

将UIView的类更改为GMSMapView 在此输入图像描述