[google-maps] Googlemaps API Key for Localhost

How do I get googlemaps api key to work on localhost?

I've created an API key and under referers I add the following:

Accept requests from these HTTP referrers (websites) (Optional)

Use asterisks for wildcards. If you leave this blank, requests will be 
accepted from any referrer. Be sure to add referrers before using this key 
in production. 

localhost

This doesnt work and if I exclude the api key it doesnt work either?

This question is related to google-maps google-maps-api-3 api-key

The answer is


Where it says "Accept requests from these HTTP referrers (websites) (Optional)" you don't need to have any referrer listed. So click the X beside localhost on this page but continue to use your key.

It should then work after a few minutes.

Changes made can sometimes take a few minutes to take effect so wait a few minutes before testing again.


You can follow this tutorial on how to use Google Maps for testing on localhost.

Check these related SO threads:

Hope this helps!


You have to check the specific error within the javascript console (e.g. Ctrl + Shift + K in Firefox for Windows).

According to Steven Gliebe (2016), there are four common cases for this problem. If I may summarize it, as this:

  1. MissingKeyMapError >> Get Google Maps API Key (but also consider alternative no.2)
  2. RefererNotAllowedMapError >> Register your localhost:port in your google developer dashboard.
  3. ApiNotActivatedMapError >> Enabling the Google Maps API in Google API Library page
  4. InvalidKeyMapError >> Add your key to your scripts/ codes properly

After doing some code modification, please clear your browser cache as necessary.

In case there are other errors, you can check Google Maps API Error Codes Documentation page.


Typing 'my IP' in google search I got my public IP address and pasted it in IP address (the third option). It works for me.


Typing 'my IP' in google search I got my public IP address and pasted it in IP address (the third option). It works for me.


If you are working on localhost, create a separate APIkey for your development and then remove restrictions on that key so that your localhost can use it. Remember to not use this key on production, so you don't expose your key to hunters online.

I had the same issue and all attempts to get the restrictions working on my localhost environment was not successful until I created a separate apikey specifically for development and then removed its restrictions. However I don't use that key on production environment, and once am done with developments, I will delete the API key immediately.

I Know this post is late, but for people that will likely face this issue in the future, this is the best route to go.


It didn't work for me when I used

http://localhost{port}/
http://localhost:{port}/something-else/here

However, removing the http did the trick for me. I just added localhost:8000 without prefixing it with the http.


Guess I'm a bit late to the party, and although I agree that creating a seperate key for development (localhost) and product it is possible to do both in only 1 key.

When you use Application restrictions -> http referers -> Website restricitions you can enter wildcard urls.

However using a wildcard like .localhost/ or .localhost:{port}. (when already having .yourwebsite.com/* ) don't seem to work.

Just putting a single * does work but this basicly gives you an unlimited key which is not what you want either.

When you include the full path withhout using the wildcard * it also works, so in my case putting:

http://localhost{port}/
http://localhost:{port}/something-else/here

Makes the Google maps work both local as on www.yourwebsite.com using the same API key.

Anyway when having 2 seperate keys is also an option I would advise to do that.


You can follow this way. It works at least for me :

in Credential page :

  1. Select option with IP address ( option no. 3 ).

  2. Put your IP address from your provider. If you don't it, search your IP address by using this link : https://www.google.com/search?q=my+ip

  3. Save it.

  4. Change your google map link as follow between the scrip tag :

    https://maps.googleapis.com/maps/api/js?libraries=places&key=AIzxxxxxxxx"

  5. Wait for about 5 minutes or more to let your API key to propagate.

Now your google map should works.