Posted By

hellofromdan on 12/07/09


Tagged


Versions (?)

Visitor Location


 / Published in: JavaScript
 

URL: http://briancray.com/2009/05/29/find-web-visitors-location-javascript-google-api/

must also load "http://www.google.com/jsapi?key=ABQIAAAAp04yNttlQq-7b4aZI_jL5hQYPm-xtd00hTQOC0OXpAMO40FHAxQMnH50uBbWoKVHwgpklyirDEregg" as a javascript

  1. <script type="text/javascript">
  2. if(google.loader.ClientLocation)
  3. {
  4. visitor_lat = google.loader.ClientLocation.latitude;
  5. visitor_lon = google.loader.ClientLocation.longitude;
  6. visitor_city = google.loader.ClientLocation.address.city;
  7. visitor_region = google.loader.ClientLocation.address.region;
  8. visitor_country = google.loader.ClientLocation.address.country;
  9. visitor_countrycode = google.loader.ClientLocation.address.country_code;
  10. document.getElementById('yourinfo').innerHTML = '<p>Lat/Lon: ' + visitor_lat + ' / ' + visitor_lon + '</p><p>Location: ' + visitor_city + ', ' + visitor_region + ', ' + visitor_country + ' (' + visitor_countrycode + ')</p>';
  11. }
  12. else
  13. {
  14. document.getElementById('yourinfo').innerHTML = '<p>Whoops!</p>';
  15. }

Report this snippet  

You need to login to post a comment.