Maps SDK for iOS: Get an API Key

Note: The Google Maps Platform Premium Plan is no longer available for sign up or new customers.

To use the Maps SDK for iOS you must have 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.

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. Click the project drop-down and select the project created for you when you purchased the Premium Plan. The project name starts with Google Maps APIs for Business or Google Maps for Work or Google Maps.
  3. Note: To have full access to the features in their plan, Premium customers should use the project associated with their Premium account. When you purchased your license, you received the name of your Premium asset in the following format: gme-[company] & proj-[number] ([type]). To ensure you are accessing the correct project, log in to the console as the project owner using console.cloud.google.com/project/number (replace number with your project number). You can locate the project owner in your welcome letter.

  4. Click the menu button and select APIs & Services > Credentials.
  5. On the Credentials page, click Create credentials > API key.
    The API key created dialog displays the newly created API key (an encrypted string).
  6. Click Close.
    The new API key is listed on the Credentials page under API keys.

Add the API key to your app

In the following examples, replace YOUR_API_KEY with your API key.

Swift

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

  1. Add the following import statement:
    import GoogleMaps
  2. Add the following to your application(_:didFinishLaunchingWithOptions:) method, replacing YOUR_API_KEY with your API key:
    GMSServices.provideAPIKey("YOUR_API_KEY")
  3. If you are also using the Places API, add your key again as shown here:
    GMSPlacesClient.provideAPIKey("YOUR_API_KEY")

Objective-C

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

  1. Add the following import statement:
    @import GoogleMaps;
  2. Add the following to your application:didFinishLaunchingWithOptions: method, replacing YOUR_API_KEY with your API key:
    [GMSServices provideAPIKey:@"YOUR_API_KEY"];
  3. If you are also using the Places API, add your key again as shown here:
    [GMSPlacesClient provideAPIKey:@"YOUR_API_KEY"];

Restrict the API key

Restricting API Keys adds security to your application by ensuring only authorized requests are made with your API Key. We strongly recommend that you follow the instructions to set restrictions for your API Keys. For more information, see API Key best practices.

To restrict an API key:

  1. In the GCP Console, on the project selector page, select or create a Google Cloud project for which you want to add an API Key.

    Go to the project selector page

  2. Go to the APIs & Services > Credentials page.

    Go to the Credentials page

  3. Select the API key that you want to set a restriction on. The API key property page appears.
  4. Under Key restrictions, set the following restrictions:
    • Application restrictions:
      1. Select iOS apps.
      2. To accept requests from the iOS app with the bundle identifier that you supply, select the appropriate iOS bundle identifier from the list.
    • API restrictions:
      1. Click Restrict key.
      2. Select Google Maps Platform Premium Plan from Select APIs dropdown.
        (If the Google Maps Platform Premium Plan is not listed, you need to enable it.)
  5. To finalize your changes, click Save.