Search code examples
google-mapsgoogle-maps-api-3api-key

Googlemaps API Key for Localhost


How do I get Google Maps API key to work on localhost?

I've created an API key and under referrers 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 doesn't work and if I exclude the API key it doesn't work, either.


Solution

    1. Go to this address: https://console.developers.google.com/apis
    2. Create new project and Create Credentials (API key)
    3. Click on "Library"
    4. Click on any API that you want
    5. Click on "Enable"
    6. Click on "Credentials" > "Edit Key"
    7. Under "Application restrictions", select "HTTP referrers (web sites)"
    8. Under "Website restrictions", Click on "ADD AN ITEM"
    9. Type your website address (or "localhost", "127.0.0.1", "localhost:port" etc for local tests) in the text field and press ENTER to add it to the list
    10. SAVE and Use your key in your project