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.
Creating API keys
You must have at least one API key associated with your project.
To get an API key:
- Go to the Google Cloud Console.
- 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.
-
Click the menu button
and select APIs & Services > Credentials.
-
On the Credentials page, click Create credentials > API key.
The API key created dialog displays the newly created API key (an encrypted string). -
Click Close.
The new API key is listed on the Credentials page under API keys.
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.
Adding 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:
- Add the following import statement:
import GoogleMaps
- Add the following to your
application(_:didFinishLaunchingWithOptions:)
method, replacing YOUR_API_KEY with your API key:GMSServices.provideAPIKey("YOUR_API_KEY")
- 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:
- Add the following import statement:
@import GoogleMaps;
- Add the following to your
application:didFinishLaunchingWithOptions:
method, replacing YOUR_API_KEY with your API key:[GMSServices provideAPIKey:@"YOUR_API_KEY"];
- If you are also using the Places API, add your key again as shown here:
[GMSPlacesClient provideAPIKey:@"YOUR_API_KEY"];
Restricting API keys
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:
-
In the Google Cloud Console, on the project selector page, select or create a Google Cloud project for which you want to add an API Key.
class="gc-analytics-event external button button-primary">Go to the project selector page
-
Go to the APIs & Services > Credentials page.
- Select the API key that you want to set a restriction on. The API key property page appears.
- Under Key restrictions, set the following restrictions:
- Application restrictions:
- Select iOS apps.
- 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:
- Click Restrict key.
- Select Google Maps Platform from Select APIs dropdown.
(If the Google Maps Platform is not listed, you need to enable it.) - To finalize your changes, click Save.