Ishwar
Ishwar

Reputation: 73

assign GMSMapView to UIView in Swift

I have created these two variables

var googleMap = GMSMapView()

@IBOutlet weak var mapView: UIView!

I'm assigning googleMap to mapView in viewDidLoad()

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

I'm providing key in AppDelegate.swift

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

Can anyone point me in the direction to solve this?

Upvotes: 4

Views: 1760

Answers (2)

Behnam Rakhshani
Behnam Rakhshani

Reputation: 563

first you should change the class of UIView to the GMSMapView from story board , then you should make a IBOutlet from that view in view controller and set camera and else like this

@IBOutlet weak var mapView: GMSMapView!    
override func viewDidLoad() {
    super.viewDidLoad()

    mapView.camera = camera
}

Upvotes: 0

LuKenneth
LuKenneth

Reputation: 2237

You do not assign the GMSMapView to your UIView in that way. Here's how you do it

Change the class of your UIView to GMSMapView enter image description here

Upvotes: 7

Related Questions