Introducing Places UI Kit: A ready-to-use, low-cost component library that lets you bring the familiar Google Maps UI for Places to any map of your choice. Try it out, andshare your input to help shape the future of GMP!

Use API Keys

Google Maps Platform products are secured from unauthorized use by restricting API calls to those that provide proper authentication credentials. These credentials are in the form of an API key - a unique alphanumeric string that associates your Google billing account with your project, and with the specific API or SDK.

This guide shows how to create, restrict, and use your API Key for Google Maps Platform.

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, seeSet up in Cloud console.

Create 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

  1. Go to theGoogle Maps Platform > Credentials page.

    Go to the Credentials page

  2. On theCredentials page, clickCreate credentials > API key.
    TheAPI key created dialog displays your newly created API key.
  3. ClickClose.
    The new API key is listed on theCredentials page underAPI keys.
    (Remember torestrict the API key before using it in production.)

Cloud SDK

gcloudservicesapi-keyscreate\--project"PROJECT"\--display-name"DISPLAY_NAME"

Read more about theGoogle Cloud SDK ,Cloud SDK installation , and the following commands:

Restrict API keys

Google strongly recommends that you restrict your API keys by limiting their usage to those onlyAPIs needed for your application. Restricting API keys adds security to your application byprotecting it from unwarranted requests.You are financially responsible for charges caused by abuse of unrestricted API keys. For more information, seeAPI security best practices.When restricting an API key in the Cloud console,Application restrictions override any APIs enabled underAPI restrictions.Follow best practices by creating a separate API key for each app, and for each platformon which that app is available.

To restrict an API key:

Console

  1. Go to theGoogle Maps Platform > Credentials page.

    Go to the Credentials page

  2. Select the API key that you want to set a restriction on. The API key property page appears.
  3. UnderKey restrictions, set the following restrictions:
    • Application restrictions:
      1. To accept requests from the list of websites that you supply, selectHTTP referers (web sites) from the list ofApplication restrictions.
      2. Specify one or more referrer websites. You can use wildcard characters to authorize all subdomains (for example,https://*.google.com accepts all sites ending in.google.com when accessed over HTTPS). Note that if you specify www.domain.com, it acts as a wildcard www.domain.com/*, and authorizes any subpath on that hostname. Only thehttps:// andhttp:// referrer schemes are supported.
    • API restrictions:
      1. ClickRestrict key.
      2. SelectMaps JavaScript API fromSelect APIs dropdown. If the Maps JavaScript API is not listed, you need toenable it.
      3. If your project uses Places Library, also selectPlaces API. Similarly, if your project uses other services in the JavaScript API (Directions Service,Distance Matrix Service,Elevation Service, and/orGeocoding Service), you must also enable and select the corresponding API in this list.
  4. To finalize your changes, clickSave.

Cloud SDK

List existing keys.

gcloudservicesapi-keyslist--project="PROJECT"

Clear existing restrictions on existing key.

gcloudservicesapi-keysupdate"projects/PROJECT/keys/KEY_ID"\--clear-restrictions

Set new restrictions on existing key.

gcloudservicesapi-keysupdateprojects/PROJECT/locations/global/keys/KEY_ID\--api-target=service=maps-backend.googleapis.com--allowed-referrers="referer"

Read more about theGoogle Cloud SDK ,Cloud SDK installation , and the following commands:

Add the API key to your request

You must include an API key with every Maps JavaScript API request.In the following example, replaceYOUR_API_KEY with yourAPI key.

<script>(g=>{varh,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});vard=b.maps||(b.maps={}),r=newSet,e=newURLSearchParams,u=()=>h||(h=newPromise(async(f,n)=>{await(a=m.createElement("script"));e.set("libraries",[...r]+"");for(king)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,...n)=>r.add(f)&&u().then(()=>d[l](f,...n))})({key:"YOUR_API_KEY",v:"weekly",// Use the 'v' parameter to indicate theversion to use (weekly, beta, alpha, etc.).// Add otherbootstrap parameters as needed, using camel case.});</script>

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-07-18 UTC.