Go Back   SitePoint Forums > Forum Index > Program Your Site > JavaScript
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
Reply
 
Thread Tools Display Modes
Old Oct 21, 2009, 14:29   #1
arthur_negas
SitePoint Enthusiast
 
Join Date: Sep 2006
Posts: 25
Google Maps API

Hi,

I am developing a site which will require a single google maps display. Until the site is ready to launch, it won't be at its domain name address but under a development IP address at my hosting company. The code for the map is:

Code:
<script src="http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=ABCDEFG&sensor=false" type="text/javascript">
</script>
<script type="text/javascript">
function initialize() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(54.179391, -0.283327), 15);
map.setUIToDefault();
}
}
</script>
Despite hours of effort, I cannot get past the following error message: The Google Maps API server rejected your request. This could be because the API key used on this site was registered for a different website.

The only two reasons I can think off for this are either that the development IP address is an issue as it is not a domain name or that I have already used my google account login for a different site but have tried setting up a different account with an alternative email address. That, or I am missing something very simple!

Any ideas would be most most welcome because I am pulling out what little of my hair that is left.

Many thanks in advance
arthur_negas is offline   Reply With Quote
Old Oct 21, 2009, 17:02   #2
Mal Curtis
Team SitePoint
 
Mal Curtis's Avatar
 
Join Date: Jul 2009
Location: Melbourne, Australia
Posts: 190
If you look in your code, the first line has a placeholder 'key' that you need to replace with your API key. It currently says 'ABCDEFG'
Mal Curtis is offline   Reply With Quote
Old Oct 22, 2009, 00:29   #3
arthur_negas
SitePoint Enthusiast
 
Join Date: Sep 2006
Posts: 25
Hi Mal,

In the actual code I am using, the full API is in place (wasn't sure if this should be published to played safe) so still not sure what the problem is.

Any suggestions welcome.
arthur_negas is offline   Reply With Quote
Old Oct 22, 2009, 05:00   #4
Mal Curtis
Team SitePoint
 
Mal Curtis's Avatar
 
Join Date: Jul 2009
Location: Melbourne, Australia
Posts: 190
Ah gotcha. I remember my students always used to get that part wrong so I jumped to a conclusion.

From memory API keys can be either specified to a domain, or to all domains. If youv'e specified a single domain I suggest creating a new API key for all domains?

I also notice that in your first script tag the first parameters are seperated with &amp; but the last is separated with just an &?
Mal Curtis is offline   Reply With Quote
Old Oct 22, 2009, 15:09   #5
wwb_99
Community Advisor
SitePoint Award Recipient
 
wwb_99's Avatar
 
Join Date: May 2003
Location: Washington, DC
Posts: 9,134
AFAIK, google maps API keys are per-domain. Our usual tactics is to push the API key into configuration and then load it from there. Since we keep separate configurations for QA versus live code, this isn't a structural problem. WRT to development work, this generally happens locally and, for localhost, the API don't care.
wwb_99 is offline   Reply With Quote
Old Oct 22, 2009, 16:37   #6
Mal Curtis
Team SitePoint
 
Mal Curtis's Avatar
 
Join Date: Jul 2009
Location: Melbourne, Australia
Posts: 190
I just tested the code you supplied, with an API key I generated and it worked no problem? Are you running it through a testing server, or just static pages?
Mal Curtis is offline   Reply With Quote
Old Oct 22, 2009, 17:14   #7
wwb_99
Community Advisor
SitePoint Award Recipient
 
wwb_99's Avatar
 
Join Date: May 2003
Location: Washington, DC
Posts: 9,134
^^^Were you testing on localhost? If so, API seems to ignore the domain stuff completely.
wwb_99 is offline   Reply With Quote
Old Oct 22, 2009, 17:17   #8
Mal Curtis
Team SitePoint
 
Mal Curtis's Avatar
 
Join Date: Jul 2009
Location: Melbourne, Australia
Posts: 190
I even tried changing the API key by deleting letters from it and it still worked :\
Mal Curtis is offline   Reply With Quote
Old Oct 22, 2009, 17:24   #9
wwb_99
Community Advisor
SitePoint Award Recipient
 
wwb_99's Avatar
 
Join Date: May 2003
Location: Washington, DC
Posts: 9,134
Right, it doesn't check at all when you are requesting from localhost, so any key will work in that scenario.
wwb_99 is offline   Reply With Quote
Old Oct 23, 2009, 21:44   #10
lana77
SitePoint Zealot
 
lana77's Avatar
 
Join Date: Jan 2005
Location: philadelphia
Posts: 156
Always request new API devkey for each domain where you place google map API code!
lana77 is offline   Reply With Quote
Old Oct 24, 2009, 01:36   #11
fabiosmith
SitePoint Member
 
Join Date: Oct 2009
Posts: 4
I am developing a site which will require a single google maps display. Until the site is ready to launch,
fabiosmith is offline   Reply With Quote
Old Oct 24, 2009, 03:12   #12
arthur_negas
SitePoint Enthusiast
 
Join Date: Sep 2006
Posts: 25
Thanks for all your help and suggestions.

Finally nailed the problem. The API key was requested for the path being used in development which is something like http://IPAddress/~tempname/dev/index.php etc

To cover the domain I had requested API for http://IPAddress/~tempname/ but got everything working when dropping the final forward slash.

Another of those frustrating scenarios where you think the problem is a bigger one that just a missing or extra full stop, slash or semi-colon!

Really appreciate all your contributions.
arthur_negas is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Sponsored Links
 
Forum Jump


All times are GMT -7. The time now is 14:52.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved