Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps API key not working

Tags:

I'm having a problem with getting my Google Maps API key to work. I originally had the problem when trying to access http://dev.domain.com using a key generated for http://domain.com, however I subsequently tried generating a key for http://dev.domain.com and it still didn't work.

I get the typical This web site needs a different Google Maps API key. A new key can be generated at http://code.google.com/apis/maps/. alert message when trying the site. Checking their FAQ and following it's instructions to alert(window.location.host) to check the domain returns dev.domain.com which looks correct (unless it's meant to have http:// at the start? In which case I don't see how I've done something wrong).

Both keys (dev.domain.com and domain.com) work correctly on localhost.

Does anyone have any ideas on what I can do to solve this or any further tests I can do to work it out?

like image 954
Blair McMillan Avatar asked Nov 26 '09 12:11

Blair McMillan


People also ask

Do Google Maps API key expire?

The fact of the matter is Public API keys don't expire. They are valid for as long as you don't delete them. So feel free to request as much public data for as long as you want, with in the limitations of your quota of course. Welcome to the would of Developing with Google!

Is Google Maps API no longer free?

You won't be charged until your usage exceeds $200 in a month. Note that the Maps Embed API, Maps SDK for Android, and Maps SDK for iOS currently have no usage limits and are at no charge (usage of the API or SDKs is not applied against your $200 monthly credit).


1 Answers

I came across this question as I was just now beating my head against this same issue. I finally noticed that the code Google provided for linking to the API was different from what I'd been using. I replaced this

<script type="text/javascript" src="http://www.google.com/jsapi?key=___">
</script>
<script type="text/javascript">
    google.load("maps", "2.x", { "language": "en" });
</script>

with this

<script type="text/javascript" 
  src="http://maps.google.com/maps?file=api&v=2&sensor=false&key=___">
</script>

and the error went away.

like image 165
Herb Caudill Avatar answered Sep 21 '22 06:09

Herb Caudill