BANGALORE, INDIA: LBS (or 'Location based services') is the new buzzword when it comes to future applications, especially in the mobile domain. This is because it provides the users with an extra context, their current location. Many applications such as Gowalla, Google Maps and Flickr use it to enhance their applications. In this article, we'll see how you, as a developer, can harness this capability in your web applications by using the W3C Geolocation API.
What is geolocation?Geolocation is the process used to find the user's current location. Many upcoming browsers, including leading mobile browsers like Opera Mobile 10.1 beta have built-in support for Geolocation.
There is an open web standard associated with geolocation, called the W3C Geolocation API. Web developers can use this API to add geolocation capabilities to their applications.
How is it better, and how does it work?One of the ways in which W3C Geolocation API is better, is that its implementation in browsers makes determination of location much more accurate. Instead of relying just on the user's IP address, the browser also tries to see information about WiFi networks nearby as well as your IP data and sends it to a location services provider which compares it with its central database of WiFi hotspots and locations to find out where you are.
Another reason it is better is that it respects the user's privacy. Before determining the location, the browser always asks whether the user wants to share his or her location or not. If the user agrees, then the location information is shared, otherwise it is not. In this way, the user has complete control on his location information, and the only way an app would know the user's location would be if it was explicitly shared.
How to use it in a web app?Using it in a web app is actually pretty easy. The W3C Geolocation API has a set of pretty straightforward functions you can use. Lets take a look at how to use it.
First of all, it is good to know whether the browser supports this capability or not. You can do so by using navigator.geoLocation.If it returns 'true', then the browser supports it, otherwise it doesn't. So your code should start with something like this:
If (navigator.geoLocation){//have your geolocation specific code here} else{//Let user know that the browser does not support geolocation, and have a fallback content ready if necessary}
So now you have the basic code to check whether the browser supports geolocation or not. Now we come to the actual implementation of finding out a user's location. One thing to know is that the user's location will be given in the form of a co-ordinate pair. One of the co-ordinates will be the longitude of the user, and the other the latitude.
Get most out of your technology infrastructure investments with Dell
About CIOL | Media Kit | Site Map | Contact Us | Help | Write to us | Jobs@CyberMedia | Privacy Policy
Copyright © CyberMedia India Online Ltd. All rights reserved. Usage of content from web site is subject to Terms and Conditions.