Know your Geolocation right away with HTML5

 Comments

Wondered how Google Maps tracks you current location? HTML5! Thats what enables most of the modern-day applications to track down your current location.

You can do it too right away!

Open up your JavaScript/Firebug console. You can hit F12 to work on most of the browsers. And paste the following JavaScript code snippet.

navigator.geolocation.getCurrentPosition(function(position){console.log(position);});

or

navigator.geolocation.getCurrentPosition(function(position){alert(position.coords.longitude + " / " + position.coords.latitude);});

Did you see a confirmation asked on your browser? Allow it! Thats it! It was so simple. You can now see your location in terms of longitude and latitude on the console. You can use this data along with Google Maps API to spot your location on a map.



Earlier and now...

Earlier, before HTML5, the user's IP was determined and so was the location tracked. Some sites provided friendly ways to do this such as http://www.geoplugin.net. With HTML5, if your browser supports HTML5, this should work whether on a mobile, tablet or on a conventional desktop. Although this way of location tracking won't show up much difference to earlier approach on a desktop, it would sure show a difference if you use it on your mobile with GPS enabled.

More to read...

The API that was used above is one of the many available for location tracking. You can read more about HTML5 location tracking at the following links:


HTML5 WEB 2.0
blog comments powered by Disqus