Playing with HTML5 GeoLocation

published on
Let me correct that subject. Geolocation is being standardized by the, which is separate from the HTML5 working group but most of the browsers along with HTML5 support is also providing support for Geolocation. To learn about Mozilla location share you can check this: Mozilla Geo Location OR for Chrome you can check this: Chrome Geo Location To understand the basics: A DOM object is provided in all new browsers (FF 3.5+ and chrome 7+[I don't count IE as browser, as usual it doesn't supports this feature also]) called navigator. A document about the same is provided here for more understanding of extended features but i will try to cover the basics in this post.Geolocation API Specification Note: Each time such code is executed your browser will ask for permission.

Enough of those reading stuffs, lets do some coding.
The above object is all about location. A sample code would be
if (navigator.geolocation) {
 navigator.geolocation.getCurrentPosition(function(position) {
 doStuff(position.coords.latitude, position.coords.longitude);
In the above code
position.coords.latitude, position.coords.longitude
will give you your current latitude and longitude. We can pass this to something and use. Say for example in my doStuff function I pass the same to google map and show the current map location. Demo: Geo Location Demo For more HTML5 resources check this. Note: Using the same data and Google map API we can use it to pre-fill registration pages like Google do for orkut registration page.