Get an API Key

To use the Maps JavaScript API 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. To learn more about API keys, see the API Key Best Practices and the FAQs.

Get the API key

You must have at least one API key associated with your project.

To get an API key:

  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 (an encrypted string).
  5. 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.)

Add 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 (the encrypted string).

  <script async defer src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap"
  type="text/javascript"></script>

Restrict the API key

Before moving your project to production, we strongly recommended that you restrict your API key. Restrictions help ensure only authorized requests are made with your API key. To learn more, see the FAQs.

To restrict an API key:

  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 Restrict and rename API key page, set the restrictions:
    • Application restrictions
      • Select HTTP referrers (web sites).
      • Add the referrers (follow the instructions).
    • API restrictions
      • Select Restrict key.
      • Click Select APIs and select Maps JavaScript API.
        (If there are other enabled APIs you want to use with this key, select them as well.)
    • Click SAVE.

Premium Plan customers

To use the Maps JavaScript API, note the following:

  • Customers with the Premium Plan can use an API key or a client ID to authenticate requests.
  • Customers with a previous license must use a client ID to authenticate requests.

Have the Premium Plan or a previous license?
To determine which license you have:
> 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 (Maps APIs for Work or Maps API for Business).

Choosing an authentication method

The section below provides a summary of the various tools and reports that are available to customers, based on the authentication method you choose.

  • Authentication using an API key (Premium Plan)
    By using an API key to authenticate your request, you can:
  • Authentication using a Client ID (Premium Plan or previous license)
    By using a client ID to authenticate your request, 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.

Authentication using an API key

To get an API key:

  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.

    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.

  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 (an encrypted string).
  5. Click Close.
    The new API key is listed on the Credentials page under API keys.
    (To continue, see Add the API key to your request and Restrict the API key.)

Authentication 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 requests 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 replace 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.

フィードバックを送信...

ご不明な点がありましたら、Google のサポートページをご覧ください。