swift - 在 Swift 中将 GMSMapView 分配给 UIView

标签 swift google-maps

我已经创建了这两个变量

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 中提供 key

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

关于swift - 在 Swift 中将 GMSMapView 分配给 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37704174/

相关文章:

ios - 如何在 iOS 中的 uitableViewCell 上显示当前位置

javascript - 未捕获的类型错误 : Cannot read property 'fitBounds' of undefined with google map( markerWithlabel js)

ios - 带有 CoreData 和 NSFetchedResultsController 的 MVVM

swift - 对 Hashable 的条件一致性

ios - 与 FacebookSDK 集成时获取个人资料信息

java - 谷歌地图,我没有找到设置的用户凭据

ios - 如何在 objective-c 中的谷歌地图上显示印度 map

java - 谷歌地图 Android fragment 崩溃

swift - 使用 Alamofire 和 SwiftyJSON 时对 JSON 进行排序

ios - 使用 Coredata 学习 Swift : why don't I get any UITableViewCells?