See which of your colleagues or former colleagues are already on Java Link: Check out the Contact Finder
News »Browse Articles » Access your visitor`s location with JavaScript API
+1
Vote Vote

Access your visitor`s location with JavaScript API

Views 7 Views    Comments 1 Comments    Share Share    Posted 07-01-2009  
Did you know Google’s JavaScript Loader API can serve up popular javascript frameworks such as jQuery, and Prototype using their content distribution network? It works like this:

google.load("prototype", "1.6");
google.load("scriptaculous", "1.8.2");

You can see a full list of supported API’s here.

Their JavaScript API now gives you access to your visitor’s location, it sets a variable google.loader.ClientLocation, and populates it with City, Region/State, Country, Latitude, Longitude.

Here’s an example:

if (google.loader.ClientLocation != null) {
document.write("Your Location Is: " +
google.loader.ClientLocation.address.city + ", "
+ google.loader.ClientLocation.address.region);
} else {
document.write("Your Location Was
Not Detected By Google Loader");
}

The avaliable properties of the google.loader.ClientLocation object are:

google.loader.ClientLocation.latitude
google.loader.ClientLocation.longitude
google.loader.ClientLocation.address.city
google.loader.ClientLocation.address.country
google.loader.ClientLocation.address.country_code
google.loader.ClientLocation.address.region

If a location cannot be determined from the visitors IP address, the google.loader.ClientLocation variable will be null.

Source:
http://www.javapronews.com/access-your-visitors-location-with-javascript-api/
+1
Vote  Vote
Enter your comment:
Pradeep 22-01-2009
This has been widely used by Google to make the user convenient by pre-selecting the user`s Area, his/her Language preference n many more things...

Search News

What's the News?

Post a link to something interesting from another site, or submit your own original writing for the Java community to read.

Most Popular News

Most Recent User Submitted News