Advertisement
Guest User

Example

a guest
Feb 3rd, 2013
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.36 KB | None | 0 0
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html>
  3.     <head>
  4.         <title>Get web visitor's location</title>
  5.         <meta name="robots" value="none" />
  6.     </head>
  7.     <body>
  8.     <div id="yourinfo"></div>
  9.     <script type="text/javascript" src="http://www.google.com/jsapi?key=ABQIAAAAp04yNttlQq-7b4aZI_jL5hQYPm-xtd00hTQOC0OXpAMO40FHAxQMnH50uBbWoKVHwgpklyirDEregg"></script>
  10.     <script type="text/javascript">
  11.         if(google.loader.ClientLocation)
  12.         {
  13.             visitor_lat = google.loader.ClientLocation.latitude;
  14.             visitor_lon = google.loader.ClientLocation.longitude;
  15.             visitor_city = google.loader.ClientLocation.address.city;
  16.             visitor_region = google.loader.ClientLocation.address.region;
  17.             visitor_country = google.loader.ClientLocation.address.country;
  18.             visitor_countrycode = google.loader.ClientLocation.address.country_code;
  19.             document.getElementById('yourinfo').innerHTML = '<p>Lat/Lon: ' + visitor_lat + ' / ' + visitor_lon + '</p><p>Location: ' + visitor_city + ', ' + visitor_region + ', ' + visitor_country + ' (' + visitor_countrycode + ')</p>';
  20.         }
  21.         else
  22.         {
  23.             document.getElementById('yourinfo').innerHTML = '<p>Whoops!</p>';
  24.         }
  25.     </script>
  26.     </body>
  27. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement