Get an API Key
Before you begin
Before you start using the Maps JavaScript API, you need a project with a billing account and the Maps JavaScript API enabled. To learn more, see Get Started with Google Maps Platform.
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:
In the Cloud 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 APIs & Services > 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.)
Adding the API key to your request
You must include an API key with every Maps JavaScript API request. In the following example, replace YOUR_API_KEY
with 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 Cloud 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 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:
- To accept requests from the list of website that you supply, select HTTP referrers (web sites) from the list of Application restrictions.
- Specify one or more referrer web sites. For example,
*.google.com
accepts all sites ending ingoogle.com
, such ashttps://developers.google.com
.Note: file:// referers need a special representation to be added to the key restriction. The "file://" part should be replaced with "__file_url__" before being added to the key restriction. For example, "file:///path/to/" should be formatted as "__file_url__//path/to/*". After enabling file:// referers, it is recommended you regularly check your usage, to make sure it matches your expectations.
- API restrictions:
- Click Restrict key.
- Select Maps JavaScript API from Select APIs dropdown.
(If the Maps JavaScript API is not listed, you need to enable it.) - If your project uses Places Library, also select Places API. Similarly, if your project uses other services in the JavaScript API (Directions Service, Distance Matrix Service, Elevation Service, and/or Geocoding Service), you must also enable and select the corresponding API in this list.
- To finalize your changes, click Save.
Source: https://developers.google.com/maps/documentation/javascript/get-api-key?utm_source=google&utm_medium=cpc&utm_campaign=FY20-Q3-global-demandgen-displayonnetworkhouseads-cs-GMP_maps_contactsal_saf_v2&utm_content=text-ad-none-none-DEV_c-CRE_374137921901-ADGP_Hybrid%20%7C%20AW%20SEM%20%7C%20BKWS%20~%20Places%20%7C%20EXA%20%7C%20Google%20Maps%20Geocoding%20API-KWID_43700046143621399-aud-596763661393%3Akwd-365407997720-userloc_1011159&utm_term=KW_google%20geocoding%20api%20key-ST_google%20geocoding%20api%20key&gclid=CjwKCAiA8Jf-BRB-EiwAWDtEGit3ksowp2GBuVKkxQCh7OIKp_oSIOlt5ELapjJl7zsbcdYS8k3dFRoC4NkQAvD_BwE
Note: This is for learning and documentation purposes.
Comments
Post a Comment