When embedding Google Maps or using Google Maps API programmatically, the calls to Google Maps API may fail with the following error message displaying on the Google Maps with exclamation mark icon on gray background, instead of displaying proper map.
Oops! Something went wrong.
Your site URL to be authorized: https://domain.name/url/
When adding approved referrers into API key restriction, Google API console provides an example if you want to use wildcards, in the following format, to match all subdomains:
However, the above format is not working properly. In fact, the above example only works if there is a subdomain in front of the domain name, e.g. www.example.com. If your website starts with just domain name, e.g. example.com only, Google Maps API may reject its authentication. In order to fix the referrer not allowed issue, try one of the following format for the URL referrers for API key restriction:
- Add actual protocol to the URL. For example:
If you need to include also the many sub-domains, try:
- If you don’t mind to risk other websites with domain name similar to yours using your API key, try the following (note that removal of dot in front of domain name):
Note that after saving the changes to key restriction, it may take up to 5 minutes for the changes to take effect.