Knowledge base / API keys

Fix RefererNotAllowedMapError on Google Maps

Your key works. Google doesn't accept the address the request came from. This is the most common reason a map renders on your own machine or staging site and fails on the live one.

How to tell this is your problem

  • The map area loads grey with the “Oops! Something went wrong.” overlay.
  • The console shows RefererNotAllowedMapError.
  • The map works on one host and not another: www.example.com but not example.com, or locally but not live.
  • It broke after a domain change, a move to HTTPS, a new staging or preview host, or someone adding restrictions to the key.

This is what the console shows:

Google Maps JavaScript API error: RefererNotAllowedMapError
https://developers.google.com/maps/documentation/javascript/error-messages#referer-not-allowed-map-error

Google's description: “The current URL loading the Maps JavaScript API has not been added to the list of allowed referrers.” The console often adds a line naming the site URL to be authorised. If it does, that string is exactly what your patterns need to match.

Why it happens

A website restriction on an API key is an allow-list. When the browser loads the Maps JavaScript API, it sends the page's address as the Referer header. Google compares that with the key's list, and anything that doesn't match is refused before a single tile is served. The usual mismatches, most likely first:

  • www versus bare domain. www.example.com/* does not match example.com, and *.example.com/* does not match it either.
  • A missing path wildcard. www.example.com on its own covers the home page only. Without /*, every other page fails.
  • A host that isn't listed. Staging, preview deployments, a second country domain, or a new domain after a rebrand.
  • A wrong port or scheme. If a pattern includes a port, only that port matches. If it includes https://, plain http:// pages won't match.
  • A path-specific pattern. Many browsers send only the origin on cross-origin requests, so patterns such as example.com/contact fail for those visitors.
  • No referrer at all. A strict Referrer-Policy header such as no-referrer on your site means Google has nothing to match.

Referrer pattern syntax

Google's API key documentation sets out these rules:

  • You can use * in place of a subdomain or a path. You can't put it in the middle of a URL, so mysubdomain*.example.com isn't valid.
  • *.example.com accepts every site ending in .example.com. The bare domain doesn't end in .example.com, so list it separately.
  • A port number is optional. With one, only that port matches. Without one, any port matches.
  • You can include the scheme, for example https://example.com/*, to accept only that scheme.
  • A key can hold up to 1,200 application restrictions, and only one restriction type at a time (websites, IP addresses, Android apps or iOS apps).
You want to allowAdd these patterns
Every page on the domain and all subdomainsexample.com/* and *.example.com/*
Every page on www onlywww.example.com and www.example.com/*
Every page on the bare domain onlyexample.com and example.com/*
A staging hoststaging.example.com/*
Local development on port 8080localhost:8080/*, preferably on a separate development key

The first row is the safe default for most sites. It covers example.com, www.example.com and any other subdomain, on any page.

The fix, step by step

  1. 01Open the failing page with the console open and note the exact host it is served from, including www and any port. If the console names a URL to authorise, copy it.
  2. 02In Google Cloud Console, open APIs & Services → Credentials in the project that owns the key, and click the key your page uses.
  3. 03Under Application restrictions, check that Websites is selected. Then look at the list of website restrictions.
  4. 04Add patterns from the table above. For most sites that means example.com/* and *.example.com/*, with your own domain in place of example.com.
  5. 05Add any other host that serves the page: staging, preview deployments, extra domains. Remove path-specific entries unless you really need them.
  6. 06Click Save. Changes can take a few minutes to apply, so wait before testing again.
Don't fix it by removing restrictions

Setting Application restrictions to None makes the error go away, but a browser key is visible in your page source. Without a website restriction, anyone can copy it and use it on their own site at your expense. Add the right patterns instead. If the key has been used elsewhere already, see rotating a leaked key.

Platform and hosting notes

  • Preview deployments. Hosts such as Netlify and Vercel give each preview its own subdomain. A wildcard for the host's domain would let other customers use your key, so use a separate development key for previews.
  • Hosted site builders. On Wix, Squarespace and Shopify, the published domain and the editor preview domain differ. The map may fail only in the editor. See platform map blocks.
  • Referrer-Policy headers. If your server or a security plugin sends Referrer-Policy: no-referrer, change it to strict-origin-when-cross-origin, which sends the origin to Google.
  • Server-side calls. Website restrictions only work for requests made from a browser. Calls to the Geocoding web service from your server send no referrer, so they need a separate key restricted by IP address.

Confirm it is fixed

Reload the page in a private window with the console open, on every host you listed: www, bare domain and staging. The error should be gone and tiles should load. If it persists after ten minutes, check you edited the key the page actually sends, and clear any page or CDN cache.

Then run a scan. It loads the page from a clean session, so it shows what a first-time visitor gets, and it reports the referrer Google refused if the error is still there.

Test your patterns before saving them with our free referrer tester. It shows which of your pages each pattern allows.

Common questions

Does *.example.com/* cover example.com without www?

No. The wildcard pattern matches sites ending in .example.com, and the bare domain doesn't. Add example.com/* as a second entry.

Why does the map work on localhost but not on my live site?

Either your local host is allowed and the live domain isn't, or you use a different key locally. Check which key the live page sends and add the live domain patterns to that key.

How long do referrer changes take to apply?

Usually a few minutes. If the error persists well after that, the page is probably still serving an old cached copy or a different key.

Can I restrict the key to a single page?

You can add a full path, but many browsers send only the origin on cross-origin requests. Visitors using those browsers will get the error, so restrict by domain instead.

Check whether this is your error

A scan tells you in about twelve seconds, from a clean session.

Related articles