|
|||||||
New to SitePoint Forums? Register here for free!
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
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&v=2.x&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>
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 |
|
|
|
|
|
#2 |
|
Team SitePoint
![]() 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'
|
|
|
|
|
|
#3 |
|
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. |
|
|
|
|
|
#4 |
|
Team SitePoint
![]() 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 & but the last is separated with just an &? |
|
|
|
|
|
#5 |
|
Community Advisor
![]() ![]() 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.
|
|
|
|
|
|
#6 |
|
Team SitePoint
![]() 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?
|
|
|
|
|
|
#7 |
|
Community Advisor
![]() ![]() 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.
|
|
|
|
|
|
#8 |
|
Team SitePoint
![]() 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 :\
|
|
|
|
|
|
#9 |
|
Community Advisor
![]() ![]() 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.
|
|
|
|
|
|
#10 |
|
SitePoint Zealot
![]() ![]() Join Date: Jan 2005
Location: philadelphia
Posts: 156
|
Always request new API devkey for each domain where you place google map API code!
|
|
|
|
|
|
#11 |
|
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,
|
|
|
|
|
|
#12 |
|
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. |
|
|
|
![]() |
| Bookmarks |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
|
All times are GMT -7. The time now is 14:52.











Linear Mode
