Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 394
Ishwar Avatar asked Mar 12 '23 01:03

Ishwar


1 Answers

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

like image 74
LuKenneth Avatar answered Mar 20 '23 13:03

LuKenneth