Visitor Location


/ Published in: JavaScript
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.