Geo locator approaches
Geolocation is a way to identify the physical location of user who is browsing this (any) web site. There are multiple approaches by which a website can get the info about physical location of an online user. HTML5 specs proposes APIs to enable this, so that the user can allow a TRUSTED site to access info about his/her location.
API looks like this:
navigator.geolocation.getCurrentPosition(successCallbackMethod, errorCallbackMethod);
If current browser support geolocation API and if it got the location successfully, then successCallbackMethod will be invoked with position as the parameter. In case of an exception, errorCallbackMethod will be invoked.
In the success call back method, you may add code to retrieve and use it according to your requirement as follows:
function successCallbackMethod (position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
.
Another point to note here is that, the browser will not share the location with out the users permission. This means, if you are accessing/browsing a web page which uses HTML5 geolocator API the first thing you will notice will be a security popup message on top of the page asking you to allow the browser to share the location, as seen in the screen shot below.
Only if you click "allow", the web page will get your location info. See the gadget application below which uses HTML5 geolocation API.
Using HTML5 APIs (will ask your permission):
There is another common way to access geolocation info that is most commonly used in web applications; which is the IP lookup method. Most of the ISPs know the location of IPs when it is assigned to any device. Most of the time, this info will fairly accurate. There are many open services available which will allow you to lookup the location from the IP address. So all you have to do is, collect the IP address coming from the browser and lookup against the IP lookup service. Below is a gadget application which gives you an fairly accurate location based on the IP address that you are currently browsing from. njoy!
Using IP lookup:
References:
Note:
Imported from my site https://sites.google.com/site/dhtmlexperiments/blogs/geolocatorapproaches dated Feb 8, 2011.
Comments
Post a Comment