当前位置 : 主页 > 手机开发 > 其它 >

在Swift中将GMSMapView分配给UIView

来源:互联网 收集:自由互联 发布时间:2021-06-11
我创建了这两个变量 var googleMap = GMSMapView()@IBOutlet weak var mapView: UIView! 我在viewDidLoad()中将googleMap指定给mapView override func viewDidLoad() { super.viewDidLoad() self.mapView = self.googleMap //Throwing error
我创建了这两个变量

var googleMap = GMSMapView()

@IBOutlet weak var mapView: UIView!

我在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'
}

我在AppDelegate.swift中提供密钥

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

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

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

将UIView的类更改为GMSMapView
enter image description here

网友评论