Script not displaying

koloth44

New member
Sep 10, 2007
20
0
0
I am not a programmer, and this is driving me nuts. I have a script using google geolocation to display user city and state.
In the < head> section I have
Code:
<script src="http://www.google.com/jsapi?key=myapikeyishere" type="text/javascript">
  </script>
and in the body I have inserted
Code:
<script type="text/javascript">
  if (typeof(google.loader.ClientLocation.address.city) != null) {
     document.write("Blah blah blah you're in " 
     + google.loader.ClientLocation.address.city + ", " 
     + google.loader.ClientLocation.address.region);
  } else { document.write("Location not detected") }
</script>
where I want the message and location to display. I set this up several months ago and it worked fine. I now go back to the site and it displays nothing, just a blank space. I have found multiple examples online of how to do this using pretty much exactly what I have. Where am I going wrong?
 


I can see one thing right off that i causing you problems. In your first bit of code there is this part "key=myapikeyishere". You need to have a key from google, it would obviously go on the right side of the equals. Keys are free and if you hit google (search) you will find where to get one. Everybody has a unique key or id they use when using google maps.

Hope this is all there is wrong.
 
Well yes, I do actually have an api key in there, I just didn't put it in the code here. Sorry, I should have made that clear!
 
Well, when I originally put in the script, the api key wasn't needed. I thought it would be fixed once I put in the key, but no dice. If there were other changes I haven't found a reference to them, and the examples online are set up like the one I'm using.
 
This works for me, no api key as found on this site.

Code:
  <script src="http://www.google.com/jsapi" type="text/javascript">
  </script>

and

Code:
<script type="text/javascript">
  if (typeof(google.loader.ClientLocation.address.city) != null) {
     document.write("Find sexy singles in " 
     + google.loader.ClientLocation.address.city + ", " 
     + google.loader.ClientLocation.address.region);
  }
</script>
 
This works for me, no api key as found on this site.

Code:
  <script src="http://www.google.com/jsapi" type="text/javascript">
  </script>
and

Code:
<script type="text/javascript">
  if (typeof(google.loader.ClientLocation.address.city) != null) {
     document.write("Find sexy singles in " 
     + google.loader.ClientLocation.address.city + ", " 
     + google.loader.ClientLocation.address.region);
  }
</script>

Doesn't work for me. So, apparently there is some other problem on my end...
 
Well, I've tried my site from multiple computers, in multiple locations, using multiple browsers and it doesn't work using the exact code DewChugr posted. I'm stumped.
 
Or you can just use this,

Code:
<script src=”http://promos.fling.com/geo/txt/location.php”></script>
 
Well, I've tried my site from multiple computers, in multiple locations, using multiple browsers and it doesn't work using the exact code DewChugr posted. I'm stumped.


Here is my entire file, line by line.

Code:
<!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>
    <title>Untitled</title>
  <script src="http://www.google.com/jsapi" type="text/javascript">
  </script>
</head>
<body>

<script type="text/javascript">
  if (typeof(google.loader.ClientLocation.address.city) != null) {
     document.write("Find sexy singles in " 
     + google.loader.ClientLocation.address.city + ", " 
     + google.loader.ClientLocation.address.region);
  }
</script>

</body>
</html>
 
Well, DewChugr, your script works for me when viewed with IE 6 from work, but doesn't when I view from home with Firefox, or IE 8. I get an error message that "google.loader.ClientLocation.address is null or not an object" So somehow the api isn't being opened right or something. I am really wondering why that is, but Howard's script does seem to work, so being lazy, I am just going to use that for now. Thanks for all your effort!

HowardRoarke, that works, thank-you!