NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
using Google Maps


Joined: 13 Oct 2006
Posts: 14
Reply with quote
In the very simple piece of HTML below, I pass google an API Key generated by using "http://localhost".

This piece of code works fine when I save it as a HTML file outside of PhpED. However, within PhpED, google rejects the API Key.

I have tried this both with a project created as "simple" using PhpED's own server and with a project using my local Apache server. Both fail. I have tried generating API key with localhost and also my IP address and all combinations fail.

Any ideas?

Thanks
Phil


Code:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>

<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=ABQIAAAARo3rnDjrzH4zIx_1B6s0yxTjI_THA_xlM7PXOf6NbLN5MiNtkRRhFTjChNow-W7fm9EPSLlmpDlRRg"></script>

<script type="text/javascript">

function initialize() {
  if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("map_canvas"));
    map.setMapType(G_NORMAL_MAP);
    map.setCenter(new GLatLng(33.48844,-117.71739), 8);
    map.addControl(new GSmallMapControl());
  }
}

</script>

</head>

   <body onload="initialize()" onunload="GUnload()" >

      <div id="map_canvas" style="width: 450px; height: 500px">



      </div>

   </body>

</html>

View user's profileFind all posts by BeerFizzSend private message
Re: using Google Maps


Joined: 17 Feb 2008
Posts: 26
Location: Alrewas, UK
Reply with quote
BeerFizz wrote:

In the very simple piece of HTML below, I pass google an API Key generated by using "http://localhost".

This piece of code works fine when I save it as a HTML file outside of PhpED. However, within PhpED, google rejects the API Key.

I have tried this both with a project created as "simple" using PhpED's own server and with a project using my local Apache server. Both fail. I have tried generating API key with localhost and also my IP address and all combinations fail.

Any ideas?


I think you are missing something - I have successfully done what you are attempting and it works fine. I have a file I call apiconfig.php:
Code:

<?
// Signup for your key at http://www.google.com/apis/maps/
if ($_SERVER['SERVER_NAME'] == 'localhost') {
    $api_key = 'ABQIAAAAnfs7bKE82qgb3Zc2YyS-oBT2yXp_ZAY8_ufC3CFXhHIE1NvwkxSySz_REpPq-4WZA27OwgbtyR3VcA' ;
} else {
$api_key = "ABQIAAAAyBxk9_kiqF9LrUeXMTBOWxTl_fGSc7veOJYLG2-ihrCS70R2AxTmKbAf-Rov_8THAH1hTZHTdO3XIg";
}
?>


Then I add a line of code at the top of the opening .php/phtml/html file and a line of code which assigns the correct key according to $_SERVER['DOCUMENT_ROOT'], thus:
Code:

<?php
include $_SERVER['DOCUMENT_ROOT'] . '\apikey.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   <title>SOW Canal Map</title>
   <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=<?php $api_key ?>" type="text/javascript"></script>   



CHeers
View user's profileFind all posts by qbusterSend private messageVisit poster's websiteAIM Address
using Google Maps
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic