Get an API Key

To use the Places SDK for iOS, you must authenticate requests using an API key. The API key is a unique identifier that is used to authenticate requests associated with your project for usage and billing purposes. To learn more, see the API Key Best Practices and the FAQs.

Get the API key

You must have at least one API key associated with your project.

To get an API key:

  1. Go to the Google Cloud Platform Console.
  2. From the Project drop-down menu, select or create the project for which you want to add an API key.
  3. From the Navigation menu, select APIs & Services > Credentials.
  4. On the Credentials page, click Create credentials > API key.
    The API key created dialog displays your newly created API key (an encrypted string).
  5. Click Close.
    The new API key is listed on the Credentials page under API keys.
    (Remember to restrict the API key before using it in production.)

Add the API key to your app

In the following examples, replace YOUR_API_KEY with your API key (the encrypted string).

Swift

Add your API key to your AppDelegate.swift as follows:

  • Add the following import statement:
    import GooglePlaces
  • Add the following to your application(_:didFinishLaunchingWithOptions:) method, replacing YOUR_API_KEY with your API key:
    GMSPlacesClient.provideAPIKey("YOUR_API_KEY")
  • If you are also using the Place Picker, add your key again as shown here:
    GMSServices.provideAPIKey("YOUR_API_KEY")
Objective-C

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

  • Add the following import statement:
    @import GooglePlaces;
  • Add the following to your application:didFinishLaunchingWithOptions: method, replacing YOUR_API_KEY with your API key:
    [GMSPlacesClient provideAPIKey:@"YOUR_API_KEY"];
  • If you are also using the Place Picker, add your key again as shown here:
    [GMSServices provideAPIKey:@"YOUR_API_KEY"];

Restrict the API key

Before moving your project to production, we strongly recommended that you restrict your API key. Restrictions help ensure only authorized requests are made with your API key. To learn more, see the FAQs.

To restrict an API key:

  1. Go to the Google Cloud Platform Console.
  2. From the Project drop-down menu, select the project that contains the API key you want to secure.
  3. From the Navigation menu, select APIs & Services > Credentials.
  4. On the Credentials page, click the name of the API key that you want to secure.
  5. On the Restrict and rename API key page, set the restrictions:
    • Application restrictions
      • Select iOS apps.
      • Add your app's bundle identifier (see the example).
    • API restrictions
      • Select Restrict key.
      • Click Select APIs and select Places API.
        (If there are other enabled APIs you want to use with this key, select them as well.)
  6. Click SAVE.

Send feedback about...