Amit Dhamu

Writes Code

Client Location From Google

When using the Google API, data about from the Client is automatically sent to Google. This information includes latitude, longtitude, city and location. You can access this data if you have a Google API Key which you can obtain for free.

Firstly, create a JavaScript code block to load the Google API.

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


Then to access the data, create a new JavaScript code block and do the following.

<script type="text/javascript">
    if(google.loader.ClientLocation) {
  var latitude = google.loader.ClientLocation.latitude;
 var longtitude = google.loader.ClientLocation.longitude;
  var city = google.loader.ClientLocation.address.city;
 var region = google.loader.ClientLocation.address.region;
 var country = google.loader.ClientLocation.address.country;
   var countrycode = google.loader.ClientLocation.address.country_code;    
    } else {
    // ClientLocation not found or not populated
  // so perform error handling
    }
</script>


Credits


google / client location / latitude / longtitude

← Conditional IE Statements AS3 Keyboard Events →