Exception:Google Maps SDK for iOS must be initialized via [GMSServices provideAPIKey:…] prior to use

前端 未结 10 1958
挽巷
挽巷 2021-01-04 12:44

I am trying to implement Google Maps SDK into my project using Swift 2.0. I follow this but when running this, my app is getting the following error:

2015-08         


        
10条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-04 13:21

    XCODE 12.0.1, Swift 5

    I was applying constraints to Google Map View by initialising GMSMapView like this:-

    private var googleMapsView : GMSMapView = {
        let mainView = GMSMapView()
        mainView.translatesAutoresizingMaskIntoConstraints = false
        mainView.isMyLocationEnabled = true
        return mainView
    }()
    

    & I was getting this same error, so I tried this making it a lazy property:-

    lazy private var googleMapsView : GMSMapView = {
        let mainView = GMSMapView()
        mainView.translatesAutoresizingMaskIntoConstraints = false
        mainView.isMyLocationEnabled = true
        return mainView
    }()
    

    & voila! It worked like a charm.

提交回复
热议问题