2015-08-25 8 views
5

Ich versuche, Google Maps SDK mithilfe von Swift 2.0 in mein Projekt zu implementieren. Ich folge dies aber, wenn dieser ausgeführt wird, meine app wird die folgende Fehlermeldung erhalten:Ausnahme: Google Maps SDK für iOS muss vor der Verwendung über [GMSServices provideAPIKey: ...] initialisiert werden

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 

Ich habe versucht, alle möglichen Lösungen von Stackoverflow.

+0

Sie meine Antwort zu sehen, müssen Sie Hinzufügen von GMSPlacesClient.provideAPIKey ("Dein Schlüssel") in appdelegate – iOS

Antwort

4

Hier ist eine Google Maps-Tutorial für Swift:

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

Unterhalb von Google Maps Dokumentation zitiert:

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

Ja, ich habe all dies..aber immer noch diese Ausnahme – iBeginner

+0

Haben Sie alle Frameworks verknüpft? – emotality

+1

Ja, ich habe alle verlinkt, die in obigem Link erwähnt sind. – iBeginner

19

Sie müssen dies in didFinishLaunchingWithOptions beide einstellen

+0

Außerdem gibt es [Migrationshinweis] (https://developers.google.com/places/migrate-to-v2) von Google. – mixel

11

Hinzufügen Nur um Rajasekaran Gopal

Denken Sie daran,

import GoogleMaps 
import GooglePlaces 

dann

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

in didFinishLaunchingWithOptions

5

Ich hatte gerade das gleiche Problem hinzuzufügen. Ich habe ein GMSMapView-Objekt erstellt und es wurde initialisiert, bevor vielleicht der api-Schlüssel gelesen werden konnte. Also habe ich es innerhalb der viewDidLoad-Methode verschoben und das Problem gelöst.

Vorher:

class ViewController: ..... { 

let mapView = GMSMapView() 

Nach:

class ViewController: ..... { 

var mapView : GMSMapView? 

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

Danke, das löst wirklich das Problem –

+0

Gleiches Problem mit mir. Vielen Dank –

3

Wenn Sie bereits GMSMapView Klasse Ihrer Ansicht in Interface Builder gesetzt, machen GMSServices.provideAPIKey("API key") in Initialisierungsmethoden von Viewcontroller, die GMSMapView enthält.

0

in meinem Fall --didFinishLaunchingWithOptions-- Methode nicht aufgerufen, weil ich Swift-Version aktualisiert. Stellen Sie zuerst sicher, dass diese Methode normal aufgerufen wird. und in meinem Fall brauchte ich nicht GMSPlacesClient.provideAPIKey ("Ihr Schlüssel"). aber Sie GMSServices in Ihrem ersten Viewcontroller initial können (wenn ich nicht Karte oder verwandte objet es enthält)

0

In meiner App zur Verfügung gestellt i Schlüssel zum GMSPlacesClient in AppDelegate -didFinishLaunchingWithOptions

Ex: 
@import GooglePlaces; 
@import GoogleMaps; 

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