2015-08-25 5 views
5

Sto cercando di implementare Google Maps SDK nel mio progetto utilizzando Swift 2.0. Seguo questo, ma quando si esegue questo, la mia app è sempre il seguente errore:Eccezione: l'SDK di Google Maps per iOS deve essere inizializzato tramite [GMSServices provideAPIKey: ...] prima dell'uso

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 

Ho provato tutte le soluzioni possibili da StackOverflow.

+0

Vedete la mia risposta, è necessario per aggiungere GMSPlacesClient.provideAPIKey ("La tua chiave") in appdelegate – iOS

risposta

4

Ecco un tutorial di Google Maps per Swift:

http://www.appcoda.com/google-maps-api-tutorial/

Di seguito è citato da Google Maps Documentazione:

Step 5: Get an iOS API key

Using an API key enables you to monitor your application's API usage, and ensures that Google can contact you about your application if necessary. The key is free, you can use it with any of your applications that call the Google Maps SDK for iOS, and it supports an unlimited number of users. You obtain an API key from the Google Developers Console by providing your application's bundle identifier.

If your project doesn't already have a key for iOS applications, follow these steps to create an API key from the Google Developers Console:

  1. In the sidebar on the left, select Credentials.
  2. If your project doesn't already have an iOS API key, create one now by selecting Add credentials > API key > iOS key.
  3. In the resulting dialog, enter your app's bundle identifier. For example: com.example.hellomap .
  4. Click Create.

    Your new iOS API key appears in the list of API keys for your project. An API key is a string of characters, something like this:

    AIzaSyBdVl-cTICSwYKrZ95SuvNw7dbMuDt1KG0

  5. Add your API key to your AppDelegate.m as follows:

    • Add the following import statement:

    @import GoogleMaps;

    • Add the following to your application:didFinishLaunchingWithOptions: method, replacing API_KEY with your API key:

    [GMSServices provideAPIKey:@"API_KEY"];

Source

+5

Sì, ho fatto tutto questo..ma ottenendo comunque quell'eccezione – iBeginner

+0

Hai collegato tutti i framework? – emotality

+1

Sì, ho collegato tutti quelli citati nel link sopra. – iBeginner

19

È necessario impostare questo sia in didFinishLaunchingWithOptions

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

Inoltre c'è [nota di migrazione] (https://developers.google.com/places/migrate-to-v2) da Google. – mixel

11

Basta aggiungere al Rajasekaran Gopal

Ricordarsi di aggiungere

import GoogleMaps 
import GooglePlaces 

poi

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

in didFinishLaunchingWithOptions

5

Ho appena avuto lo stesso problema. Ho creato un oggetto GMSMapView ed è stato inizializzato prima di poter leggere la chiave API. Quindi l'ho spostato all'interno del metodo viewDidLoad e il problema è stato risolto.

Prima:

class ViewController: ..... { 

let mapView = GMSMapView() 

Dopo:

class ViewController: ..... { 

var mapView : GMSMapView? 

override viewDidLoad(){ 
    mapView = GMSMapView() 
+0

Grazie, questo risolve davvero il problema –

+0

Stesso problema con me. Grazie –

3

Se già impostato GMSMapView classe alla vostra vista in Interface Builder, fare GMSServices.provideAPIKey("API key") nei metodi di inizializzazione di viewController che contiene GMSMapView.

0

nel mio caso --didFinishLaunchingWithOptions-- il metodo non ha chiamato perché ho aggiornato la versione rapida. per prima cosa assicurati che questo metodo venga chiamato normalmente. e nel mio caso non avevo bisogno di GMSPlacesClient.provideAPIKey ("La tua chiave"). tuttavia è possibile siglare GMSServices nel viewcontroller iniziale (se non contengono carta o correlati ad esso objet)

0

Nella mia app ho fornito la chiave per GMSPlacesClient in AppDelegate -didFinishLaunchingWithOptions

Ex: 
@import GooglePlaces; 
@import GoogleMaps; 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
    [GMSServices provideAPIKey:@"You key"]; 
    [GMSPlacesClient provideAPIKey:@"Your key"]; 
}