New pricing changes went into effect on July 16, 2018. For more information, check out the Guide for Existing Users.

Get API Key

To use the Maps JavaScript API, you must get an API key which you can then add to your mobile app, website, or web server.  The API key is used to track API requests associated with your project for usage and billing. To learn more about API keys, see the API Key Best Practices and the FAQs.

Console

You can use the Google Cloud Platform Console to manage projects, get API keys, and add API key restrictions. For more information about the console, see the Google Cloud Platform Console Help.

Quick guide

Step 1: Get an API key

Click the button below, to get an API key using the Google Cloud Platform Console. You will be asked to (1) pick one or more products, (2) select or create a project, and (3) set up a billing account. Once your API key is created you will be prompted to restrict the key's usage. (For more information, see Restricting an API key.)

Get Started

Step 2: Add the API key to your code

When loading the 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>

Detailed guide

Follow these steps to get an API key and add restrictions:

  1. Go to the Google Cloud Platform Console.
  2. From the Project drop-down menu, select or create the project for which you want to add an API key.
  3. From the Navigation menu, select APIs & Services > Credentials.
  4. On the Credentials page, click Create credentials > API key.
    The API key created dialog displays your newly created API key.
  5. On the dialog, click Restrict Key.
    (For more information, see Restricting an API key.)
  6. On the API key page, under Key restrictions, set the Application restrictions.
    • Select HTTP referrers (web sites).
    • Add the referrers (follow the instructions).
    • Click Save.

Detailed guide for Premium Plan customers

When using the 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:
  • Authentication using a Client ID
    By using your client ID (instead of an API key) to authenticate your application, you can:
    • Add the channel parameter 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.

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 the Premium Plan or a previous license?
To determine which license you have (for Maps APIs for Work or Maps API for Business):
> In the Google Cloud Support Portal, click Maps: Usage Report on the left.
> Does the ID at the top of the report have the following format?
   gme-[company] & proj-[number] ([type])
If yes, you have the Premium Plan. If no, you have a previous license.

Authenticating your application using an API key

Follow these steps to get an API key and add restrictions:

  1. Go to the Google Cloud Platform Console.
  2. 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.
  3. From the Navigation menu, select APIs & Services > Credentials.
  4. On the Credentials page, click Create credentials > API key.
    The API key created dialog displays your newly created API key.
  5. On the dialog, click Restrict Key.
    (For more information, see Restricting an API key.)
  6. On the API key page, under Key restrictions, set the Application restrictions.
    • Select HTTP referrers (web sites).
    • Add the referrers (follow the instructions).
    • Click Save.

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 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 Maps JavaScript API.

  <script async defer
  src="https://maps.googleapis.com/maps/api/js?client=YOUR_CLIENT_ID&v=quarterly&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=quarterly 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.

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:

  1. Log in to the Google Cloud Support Portal.
  2. In the left-hand menu, click Maps: Manage Client ID.

You can add up to 100 URLs at a time. A Client ID may be associated with up to 3000 authorized URLs. If you expect your application to host Google Maps content from more than 3000 locations, you should switch to using API keys instead.

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://myintranet and http://192.168.1.1 are valid entries.
All subdomains of a specified domain are also authorized.
For example, if http://example.com is authorized, then http://www.example.com is also authorized. The reverse is not true: if http://www.example.com is authorized, http://example.com is not necessarily authorized.
All subpaths of an authorized path are also authorized.
For example, if http://example.com is authorized, then http://example.com/foo is also authorized. In addition, because subdomains of a specified domain are also authorized, http://sub.example.com/bar is authorized.
Paths are case sensitive.
For example, http://www.example.com/ThisPath/ is not the same as http://www.example.com/thispath/.
You may restrict valid URLs to those using certain ports.
For example, if http://example.com:8080/foo is specified, that doesn't authorize http://example.com.
HTTP and HTTPS protocols are considered different URLs.
For example, if https://example.com is authorized, http://example.com is 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.

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 an unrestricted API key. However, you have the option to add a restriction to the API key. Once restricted, the key will only work on platforms that support that type of restriction.

To add restrictions for an API key, do the following:

  1. Go to the Google Cloud Platform Console.
  2. From the Project drop-down menu, select the project that contains the API key you want to secure.
  3. From the Navigation menu, select APIs & Services > Credentials.
  4. On the Credentials page, click the name of the API key that you want to secure.
  5. On the API key page, under Key restrictions, set the Application restrictions.
    • Select HTTP referrers (web sites).
    • Add the referrers (follow the instructions).
    • 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.

Send feedback about...

Maps JavaScript API
Need help? Visit our support page.