To use the Google Maps JavaScript API, you must register your app project on the Google API Console and get a Google API key which you can add to your app.
Quick guide to getting a key
Step 1: Get an API Key from the Google API Console
Click the button below, which guides you through the process of registering a project in the Google API Console, activates the Google Maps JavaScript API and any related services automatically, and generates a generic, unrestricted API key.
Get a KeyNotes:
- Tip: During development and testing, you can register a project for testing purposes in the Google API Console and use a generic, unrestricted API key. When you are ready to move your app or website into production, register a separate project for production, create a browser-restricted API key, and add the key to your application.
- Premium Plan customers: For production-ready apps, you must use a browser-restricted API key that is set up in the Google Maps APIs Premium Plan project created for you when you purchased the Premium Plan. Alternatively, you can use a client ID in combination with URL registration (instead of an API key).
- For more information, see the detailed guides below for Standard Plan and Premium Plan customers.
Step 2: Add the API key to your application
When loading the Google Maps JavaScript API, substitute YOUR_API_KEY in the code below with the
API key you got from the previous step.
<script async defer src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap" type="text/javascript"></script>
More about API keys
- The API key allows you to monitor your application's API usage in the Google API Console. See Google API Console help for more information.
- If you are a Standard Plan customer, with an API key you have access to generous free daily quota, as well as the option to increase your daily quota by enabling pay-as-you-go billing.
- If you are a Premium Plan customer, you must use an API key or your client ID to access all the custom features and benefits of your Premium Plan.
- Registering for an API key ensures that Google can contact you about your application if necessary.
Detailed guide for users of the standard Google Maps JavaScript API
Follow these steps to get an API key:
- Go to the Google API Console.
- Create or select a project.
- Click Continue to enable the API and any related services.
-
On the Credentials page, get an API key.
Note: If you have an existing unrestricted API key, or a key with browser restrictions, you may use that key. - From the dialog displaying the API key, select Restrict key to set a browser restriction on the API key.
- In the Key restriction section, select HTTP referrers (web sites), then follow the on-screen instructions to set referrers.
- (Optional) Enable billing. See Usage Limits for more information.
In the Google API Console, you can also
look up an existing key or
view a list of enabled APIs.
For more information on using the Google API Console, see API Console Help.
Detailed guide for users of the Google Maps APIs Premium Plan license
When using the Google Maps JavaScript API with a
Google Maps APIs Premium Plan license,
you must authenticate your application with either an API key or a client ID.
Note: If you have a previous Maps
API for Business license, you must use a client ID, not an API key.
Choosing an authentication method for your application
The section below provides a summary of the various tools and reports that are available to Premium Plan customers, based on the method you choose to authenticate your application.
- Authentication using an API key
(Note: Customers with a current Premium Plan license may use an API key, but customers holding a previous Maps API for Business license must use a client ID.)
By using an API key to authenticate your applications, you can:- Manage all of your APIs in the Google API Console.
- Access real-time usage data and 30 days of historical usage data for your application in the Google API Console.
- View usage reports with more than 30 days of data in the Google Cloud Support Portal.
- Authentication using a Client ID
By using your client ID (instead of an API key) to authenticate your application, you can:- Add the
channelparameter to requests so you can view more detailed usage reports. - View usage reports with more than 30 days of data in the Google Cloud Support Portal.
- Use Maps Analytics tools for the Maps JavaScript API.
- Add the
Get more information on reports available to Premium Plan customers.
Note: The information below on using an API key applies only to the Google Maps APIs Premium Plan, which became available on January 6, 2016.
Have a previous
Maps APIs for Work or Maps API for Business license?
See our Maps APIs for Work
Licenses guide. To determine whether you have a previous license: In the
Google Cloud Support Portal,
click Maps: Usage Report on the left. If the ID at the top of the report
is in the following format, you have the new Premium Plan:
gme-[company] & proj-[number] ([type])
Otherwise, you have a previous license.
Authenticating your application using an API key
Follow these steps to get an API key:
- Go to the Google API Console.
- From the Project drop-down menu, 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. Important: If you have a previous Maps API for Business license, you must use a client ID, not an API key.
- Click Continue.
-
On the Credentials page, get an API key.
Note: If you have an existing unrestricted API key, or a key with browser restrictions, you may use that key. - From the dialog displaying the API key, select Restrict key to set a browser restriction on the API key.
- In the Key restriction section, select HTTP referrers (web sites), then follow the on-screen instructions to set referrers.
You can also
look up an existing key in the Google API Console.
For more information on using the Google API Console, see API Console Help.
Authenticating your application using a client ID
Upon purchasing your Google Maps APIs Premium Plan license, you will receive a welcome email from Google that contains your client ID, which allows to access the various reports and tools of the Google Maps APIs Premium Plan.
All client IDs begin with a gme- prefix. Below is the format of a typical client ID.
gme-[company] & proj-[number] ([type])
You can authenticate your application with the Google Maps JavaScript API using a client ID in combination with URL registration (instead of an API key).
Note: This client ID is not a key, and it can only be used by URLs that you authorize. Read more about registering authorized URLs.
Specifying a client ID when loading the API
The code below shows you how to substitute YOUR_CLIENT_ID with your own client ID when loading the Google Maps JavaScript API.
<script async defer src="https://maps.googleapis.com/maps/api/js?client=YOUR_CLIENT_ID&v=3.29&callback=initMap"></script>
You must specify the release version (also
referred to as the feature-stable version) or an earlier version, by appending a
v=3.29 parameter. Applications that use the experimental version are not
covered under the Google Maps APIs Premium Plan SLA.
Note:
If you were previously using an API key for authentication and are switching to
using a client ID, you must remove the key parameter before loading
the API. The API will fail to load if both a client ID and an API key are
included.
Restricting an API key
Google Maps APIs are available for web browsers, Android or iOS apps, and via HTTP web services. APIs in any platform can use a generic (unrestricted) API key. You can optionally add a restriction (for example, HTTP referrer) to the API key. Once restricted, a key will only work on platforms that support that type of restriction.
Tip: Before moving your app or website to production, you should secure your API key. Keys for the Google Maps JavaScript API use the HTTP referrers (web sites) key restriction. Learn more about keys and credentials.
To add web browser restrictions to an existing, generic API key, do the following:
- Go to the Credentials page of the Google API Console.
- Select the project that contains the API key you want to edit.
- On the Credentials page, from the list of API keys, select the name of the API key to edit the details of the key.
- In the Key restriction section of the page, select HTTP referrers (web sites), follow the on-screen instructions to set referrers, then click Save.
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.
Registering authorized URLs
To prevent a third party from using your client ID on their own website, the use of your client ID is restricted to a list of URLs that you specifically authorize.
To see the URLs you have already authorized or to authorize additional URLs:
- Log in to the Google Cloud Support Portal.
- In the left-hand menu, click Maps: Manage Client ID.
You can add up to 100 URLs at a time, to a total of 3000 URLs. If you require higher limits, please contact support.
The following considerations apply regarding URLs that are authorized:
- The domain name or IP address does not have to be publicly accessible.
- For example,
http://myintranetandhttp://192.168.1.1are valid entries. - All subdomains of a specified domain are also authorized.
- For example, if
http://example.comis authorized, thenhttp://www.example.comis also authorized. The reverse is not true: ifhttp://www.example.comis authorized,http://example.comis not necessarily authorized. - All subpaths of an authorized path are also authorized.
- For example, if
http://example.comis authorized, thenhttp://example.com/foois also authorized. In addition, because subdomains of a specified domain are also authorized,http://sub.example.com/baris authorized. - Paths are case sensitive.
- For example,
http://www.example.com/ThisPath/is not the same ashttp://www.example.com/thispath/. - You may restrict valid URLs to those using certain ports.
- For example, if
http://example.com:8080/foois specified, that doesn't authorizehttp://example.com. - HTTP and HTTPS protocols are considered different URLs.
- For example, if
https://example.comis authorized,http://example.comis not necessarily authorized. If you'd like to authorize both at once, you may add a domain without using a protocol:example.com/
All the rules above are applied to each authorization, so you should take care to plan your authorizations carefully. For example, because all subpaths of a specified path are authorized, and all subdomains, you may end up authorizing pages that you didn't intend to. For example:
http://example.com/ also authorizes
http://sub.example.com/path.
For more information, see Troubleshooting Google Maps APIs Premium Plan Authorization.
