Home IT companies Where is my user from?

Where is my user from?

by admin

Have you ever used a trick in your web applications such as centering a Google map by the user’s location? Let’s look at a small map example. Wasn’t it great when you displayed the map to have it show the current user’s country, region, city, etc., rather than just centered on Los San Francisco or Australia?
Let’s take a look at the new "API." Actually, it’s not really an API, it’s just a property of google.loader.ClientLocation
After loading any part of Google’s AJAX API, the system will try to find the client’s geographic location by its ip address.
If there is a match between maps and the client’s ip address, google.loader.ClientLocation returns the approximate coordinates of the user’s country, region, city. The mapping is far from perfect, but it allows you to use smart defaults or show your awareness of the visitor’s location in your projects.
Here’s a simple example of using google.loader.ClientLocation:

* Set the currentState_ and currentCountry_ properties based on the client's
* current location (when available and in the US), or to the defaults.
InTheNews.prototype.setDefaultLocation_ = function () {
this currentState_ = this options_.startingState;
if (google.loader.ClientLocation
google.loader.ClientLocation.address.country_code == "US"
google.loader.ClientLocation.address.region) {
// geo locate was successful and user is in the states. range check
// the region so that we can safely use it when selecting a state
// level polygon overlay
var state = google.loader.ClientLocation.address.region.toUpperCase();
if (InTheNews.stateNames[[]state]) {
this currentState_ = state;
this currentCountry_ = "US" ;
* This source code was highlighted with Source Code Highlighter

To see how the code works, visit States 2008 election page. If you go to the "News by State" section, you will see either news about the candidate from the state you are in, or, if there is no map coordinate match with your ip address, news about the candidate from the state of California.
Now for the nice stuff. If you like the mechanism of matching an ip address to a visitor’s location, then it’s worth waiting to see what the Gears team has in store for you. They are preparing the final version of this functionality, which can determine coordinates by ip address, GPS and soon WiFi. This is definitely a leap in the direction of improving both functionality and accuracy.

You may also like