Getting an API Key
Now that you've set up billing and a project, enabled the SDK, and installed your preferred dependency manager and other software, you're prepared to create, add, and restrict your API key.
Creating API keys
The API key is a unique identifier that authenticates requests associated with your project for usage and billing purposes. You must have at least one API key associated with your project.
To create an API key:
Console
-
Go to the Google Maps Platform > Credentials page.
-
On the Credentials page, click Create credentials > API key.
The API key created dialog displays your newly created API key. -
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.)
Cloud SDK
gcloud alpha services api-keys create \ --project "PROJECT" \ --display-name "DISPLAY_NAME"
Read more about the Google Cloud SDK , Cloud SDK installation , and the following commands:
You need this API key when you create your Xcode project as described in Set up an Xcode Project.
Restricting API keys
Google strongly recommends that you restrict your API keys by limiting their usage to those only APIs needed for your application. Restricting API keys adds security to your application by protecting it from unwarranted requests. For more information, see API security best practices.
To restrict an API key:
Console
-
Go to the Google Maps Platform > 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 Maps SDK for iOS from Select APIs dropdown. If the Maps SDK for iOS is not listed, you need to enable it.
- To finalize your changes, click Save.
Cloud SDK
List existing keys.
gcloud services api-keys list --project="PROJECT"
Clear existing restrictions on existing key.
gcloud alpha services api-keys update "projects/PROJECT/keys/KEY_ID" \ --clear-restrictions
Set new restrictions on existing key.
gcloud alpha services api-keys update projects/PROJECT/locations/global/keys/KEY_ID \ --api-target=service=maps-ios-backend.googleapis.com --allowed-bundle-ids="BUNDLE_NAME"
Read more about the Google Cloud SDK , Cloud SDK installation , and the following commands:
Now that you've gotten your API key for Maps SDK for iOS, you're ready to get started.
What's next
Now that you have an API key, create and configure your Xcode project as described in Set up an Xcode Project.