Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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-25 19:05:17.337 googleMap[1919:54102] *** Terminating app due to uncaught exception 'GMSServicesException', reason: 'Google Maps SDK for iOS must be initialized via [GMSServices provideAPIKey:...] prior to use
*** First throw call stack:
(
    0   CoreFoundation    0x00000001058499b5 __exceptionPreprocess + 165
...
...
...
    31  UIKit             0x000000010606699e UIApplicationMain + 171
    32  googleMap         0x00000001034b720d main + 109
    33  libdyld.dylib     0x0000000107fba92d start + 1
    34  ???               0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

I have tried all possible solutions from StackOverflow.

like image 307
iBeginner Avatar asked Aug 25 '15 13:08

iBeginner


3 Answers

You need to set this both in didFinishLaunchingWithOptions

GMSPlacesClient.provideAPIKey("Your key")
GMSServices.provideAPIKey("Your key")
like image 147
Rajasekaran Gopal Avatar answered Dec 04 '22 06:12

Rajasekaran Gopal


Just adding to Rajasekaran Gopal

Remember to add

import GoogleMaps
import GooglePlaces

then

GMSPlacesClient.provideAPIKey("Your key")
GMSServices.provideAPIKey("Your key")

in didFinishLaunchingWithOptions

like image 41
Vu Tran Avatar answered Dec 04 '22 08:12

Vu Tran


I just had the same problem. I created a GMSMapView object and it was initialized before maybe the api key could be read. So I moved it inside the viewDidLoad method and problem solved.

Before :

class ViewController: ..... {

let mapView = GMSMapView()

After :

class ViewController: ..... {

var mapView : GMSMapView?

override viewDidLoad(){
    mapView = GMSMapView()
like image 25
Jasveer Avatar answered Dec 04 '22 07:12

Jasveer