Google's Geocoding web service rejects a key that is locked to websites
Fix it fast
Most common cause, 1 of 2Browser JavaScript calls the Geocoding web service URL with the website key
Use the Geocoding service that is part of the Maps JavaScript API instead.
const { Geocoder } = await google.maps.importLibrary("geocoding");
const geocoder = new Geocoder();
const { results } = await geocoder.geocode({
address: "1600 Amphitheatre Parkway, Mountain View, CA",
});
console.log(results[0].formatted_address, results[0].geometry.location.toString());Short answer
Google Maps web services such as the Geocoding API reject website-restricted keys with REQUEST_DENIED and 'API keys with referer restrictions cannot be used with this API.' In browser code, use the Maps JavaScript API Geocoder, which accepts website keys. On a server, use a second key restricted to its IP addresses. Applies to Google Maps Platform, Nov 2026.
Which cause do you have?
Find every place that calls a Maps web service URL directly. A hit in front-end code (React, plain script tags) means cause 1. A hit in back-end code (Node, PHP, Python, a cron job) means cause 2.
grep -rn "maps.googleapis.com/maps/api/" src app server lib public 2>/dev/nullThen find the line you see in this list and open its fix:
- 1Browser JavaScript calls the Geocoding web service URL with the website key
The browser's Network tab shows a request to maps.googleapis.com/maps/api/geocode/json sent by your page, and the key is the one that loads your map - 2Server code reuses the key that is restricted to your website
The request comes from your back end, and its key string is the same one embedded in your web pages
What does the error look like?
API keys with referer restrictions cannot be used with this API.API keys cannot have referer restrictions when used with this API."status" : "REQUEST_DENIED"
Cause 1 of 2
Browser JavaScript calls the Geocoding web service URL with the website key
You seeThe browser's Network tab shows a request to maps.googleapis.com/maps/api/geocode/json sent by your page, and the key is the one that loads your map
Check
The REQUEST_DENIED referer message means a web service API received a key with HTTP referrer restrictions. Google's FAQ says web services must be called with keys restricted to IP addresses for security reasons. A page that builds a geocode/json URL in fetch or axios is calling the web service, even though it runs in a browser.
grep -rn "geocode/json" src public 2>/dev/nullFix
Use the Geocoding service that is part of the Maps JavaScript API instead. Google lists it under the Websites restriction type, so the key you already use for the map keeps working. The Geocoding API still has to be enabled in the Cloud project.
const { Geocoder } = await google.maps.importLibrary("geocoding");
const geocoder = new Geocoder();
const { results } = await geocoder.geocode({
address: "1600 Amphitheatre Parkway, Mountain View, CA",
});
console.log(results[0].formatted_address, results[0].geometry.location.toString());Verify
The console prints an address and coordinates, and the Network tab no longer shows a geocode/json request answered with REQUEST_DENIED.
grep -rn "geocode/json" src public 2>/dev/null || echo "no direct web service calls left"Confirmed by developers.google.com
Cause 2 of 2
Server code reuses the key that is restricted to your website
You seeThe request comes from your back end, and its key string is the same one embedded in your web pages
Check
Google's web services reject a website-restricted key no matter which machine sends the request, and one key can hold only one kind of application restriction: the API Keys reference allows either browser (referrer) or server (IP) restrictions on a key, not both. So switching the shared key to IP addresses would break the map in the browser.
gcloud services api-keys describe KEY_ID --project=PROJECT_IDFix
Create a second key for the server, limited to the Geocoding API and to the public IP addresses your server uses, and keep it in an environment variable rather than in code. Leave the first key restricted to your websites for the map.
gcloud services api-keys create \
--project=PROJECT_ID \
--display-name="geocoding-server" \
--api-target=service=geocoding-backend.googleapis.com \
--allowed-ips=203.0.113.10Verify
A request from the server with the new key returns status OK and results.
curl -s "https://maps.googleapis.com/maps/api/geocode/json?address=Washington&key=$GEOCODING_SERVER_KEY" | grep '"status"'Confirmed by developers.google.com
How do I stop it coming back?
- Keep two keys from the start: one restricted to websites for the Maps JavaScript API, one restricted to server IPs for web services.
- When the server runs on hosting with changing IPs, follow Google's advice for that case and send web service calls through a proxy server instead of dropping the restriction.
- Store the server key in a secret manager or environment variable and never ship it in front-end bundles.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: stegnor.com.