[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-20 UTC."],[[["\u003cp\u003eGoogle Maps Platform requires an API key for authentication and billing purposes, associating your project with a unique alphanumeric string.\u003c/p\u003e\n"],["\u003cp\u003eYou can create and manage API keys via the Google Cloud Console or the Cloud SDK, enabling access and specifying restrictions for security.\u003c/p\u003e\n"],["\u003cp\u003eRestricting API keys is highly recommended, limiting usage to specific applications and websites for enhanced security.\u003c/p\u003e\n"],["\u003cp\u003eInclude your API key in every Maps JavaScript API request, replacing \u003ccode\u003eYOUR_API_KEY\u003c/code\u003e in the provided script snippet.\u003c/p\u003e\n"]]],["Google Maps Platform requires API keys for authentication and billing. To create an API key, navigate to the Google Maps Platform Credentials page and select \"Create credentials \\\u003e API key.\" Restricting API keys to specific applications and APIs is strongly recommended for security and to prevent financial abuse. This can be done via the console or Cloud SDK by setting application and API restrictions. Finally, include the API key in every Maps JavaScript API request.\n"],null,["Google Maps Platform products are secured from unauthorized use by restricting API calls\nto those that provide proper authentication credentials. These credentials are in the form of\nan API key - a unique alphanumeric string that associates your Google billing account with your\nproject, and with the specific API or SDK.\n\nThis guide shows how to create, restrict, and use your API Key for Google Maps Platform.\n\nBefore you begin\n\nBefore you start using the Maps JavaScript API, you need a project with a billing account and the\nMaps JavaScript API enabled. To learn more, see [Set up in Cloud console](/maps/documentation/javascript/cloud-setup).\n\nCreate API keys\n\nThe API key is a unique identifier that authenticates requests associated with your project for\nusage and billing purposes. You must have at least one API key associated with your project.\n\nTo create an API key:\n\nConsole \n\n1. Go to the **Google Maps Platform \\\u003e Credentials** page.\n\n [Go to the Credentials page](https://console.cloud.google.com/project/_/google/maps-apis/credentials?utm_source=Docs_CreateAPIKey&utm_content=Docs_maps-backend)\n2. On the **Credentials** page, click **Create credentials \\\u003e API key** . \n The **API key created** dialog displays your newly created API key.\n3. Click **Close.** \n The new API key is listed on the **Credentials** page under **API keys** . \n (Remember to [restrict the API](/maps/api-security-best-practices#restricting-api-keys) key before using it in production.)\n\nCloud SDK \n\n```bash\ngcloud services api-keys create \\\n --project \"\u003cvar translate=\"no\"\u003ePROJECT\u003c/var\u003e\" \\\n --display-name \"\u003cvar translate=\"no\"\u003eDISPLAY_NAME\u003c/var\u003e\"\n```\n\nRead more about the\n[Google Cloud SDK](https://cloud.google.com/sdk)\n,\n[Cloud SDK installation](https://cloud.google.com/sdk/docs/install)\n, and the following commands:\n\n- [`gcloud services api-keys create`](https://cloud.google.com/sdk/gcloud/reference/services/api-keys/create)\n\nRestrict API keys\n\nGoogle strongly recommends that you restrict your API keys by limiting their usage to those only\nAPIs needed for your application. Restricting API keys adds security to your application by\nprotecting it from unwarranted requests. **You are financially responsible for charges caused by abuse of unrestricted API keys.** For more information, see\n[API security best practices](/maps/api-security-best-practices#restrict_apikey).\n\n| When restricting an API key in the Cloud console, **Application restrictions** override any APIs enabled under **API restrictions**. Follow best practices by creating a separate API key for each app, and for each platform on which that app is available.\n\nTo restrict an API key:\n\nConsole\n\n1. Go to the **Google Maps Platform \\\u003e Credentials** page.\n\n [Go to the Credentials page](https://console.cloud.google.com/project/_/google/maps-apis/credentials?utm_source=Docs_RestrictAPIKey&utm_content=Docs_maps-backend)\n2. Select the API key that you want to set a restriction on. The API key property page appears.\n3. Under **Key restrictions**, set the following restrictions:\n - Application restrictions:\n 1. To accept requests from the list of websites that you supply, select **HTTP\n referers (web sites)** from the list of **Application\n restrictions**.\n 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 the `https://` and `http://` referrer schemes are supported.\n - API restrictions:\n 1. Click **Restrict key**.\n 2. Select **Maps JavaScript API** from **Select APIs** dropdown. If the Maps JavaScript API is not listed, you need to [enable](/maps/documentation/javascript/cloud-setup#enabling-apis) it.\n 3. If your project uses Places Library, also select **Places API** . Similarly, if your project uses other services in the JavaScript API ([Directions Service](/maps/documentation/javascript/directions), [Distance Matrix Service](/maps/documentation/javascript/distancematrix), [Elevation Service](/maps/documentation/javascript/elevation), and/or [Geocoding Service](/maps/documentation/javascript/geocoding)), you must also enable and select the corresponding API in this list.\n4. To finalize your changes, click **Save** . \n\nCloud SDK\n\n\nList existing keys. \n\n```bash\ngcloud services api-keys list --project=\"\u003cvar translate=\"no\"\u003ePROJECT\u003c/var\u003e\"\n```\n\n\nClear existing restrictions on existing key. \n\n```bash\ngcloud services api-keys update \"projects/\u003cvar translate=\"no\"\u003ePROJECT\u003c/var\u003e/keys/\u003cvar translate=\"no\"\u003eKEY_ID\u003c/var\u003e\" \\\n --clear-restrictions\n```\n\n\nSet new restrictions on existing key. \n\n```bash\ngcloud services api-keys update projects/PROJECT/locations/global/keys/KEY_ID \\\n --api-target=service=maps-backend.googleapis.com\n --allowed-referrers=\"\u003cvar translate=\"no\"\u003ereferer\u003c/var\u003e\"\n```\n\nRead more about the\n[Google Cloud SDK](https://cloud.google.com/sdk)\n,\n[Cloud SDK installation](https://cloud.google.com/sdk/docs/install)\n, and the following commands:\n\n- [`gcloud services api-keys update`](https://cloud.google.com/sdk/gcloud/reference/services/api-keys/update)\n- [`gcloud services api-keys lookup`](https://cloud.google.com/sdk/gcloud/reference/services/api-keys/lookup)\n- [`gcloud services api-keys list`](https://cloud.google.com/sdk/gcloud/reference/services/api-keys/list)\n\nAdd the API key to your request\n\n\nYou must include an API key with every Maps JavaScript API request.\nIn the following example, replace `YOUR_API_KEY` with your\nAPI key. \n\n```javascript\n\u003cscript\u003e\n (g=\u003e{var h,a,k,p=\"The Google Maps JavaScript API\",c=\"google\",l=\"importLibrary\",q=\"__ib__\",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=\u003eh||(h=new Promise(async(f,n)=\u003e{await (a=m.createElement(\"script\"));e.set(\"libraries\",[...r]+\"\");for(k in g)e.set(k.replace(/[A-Z]/g,t=\u003e\"_\"+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=()=\u003eh=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)=\u003er.add(f)&&u().then(()=\u003ed[l](f,...n))})({\n key: \"YOUR_API_KEY\",\n v: \"weekly\",\n // Use the 'v' parameter to indicate the /maps/documentation/javascript/versions to use (weekly, beta, alpha, etc.).\n // Add other /maps/documentation/javascript/load-maps-js-api#required_parameters as needed, using camel case.\n });\n\u003c/script\u003e\n```"]]