| |
Last
Updated:
|
How To Add Geolocation Support To Your Site
By Mads Kristensen
Expert Author Article Date: 2008-11-24 The W3C has created a standard for location sharing called Geolocation. It allows any person to share her location with any website at the click of a button. Imagine the possibilities with this. Here is a scenario: You've arrived in a new city, a new continent, a new coffee shop. You don't really know where you are, and are looking for a good place to eat. You pull out your laptop, fire up Firefox, and go to your favorite review site. It automatically deduces your location, and serves up some delicious suggestions a couple blocks away and plots directions there. Firefox 3.1 will have this build in, but until then we can use a Firefox add-on called Geode. Basically, it uses your Wi-Fi network to find your exact location and then passes it to a JavaScript callback method on your website. Already now, services like Pownce, Fire Eagle and ZYB uses this to improve the user experience of their services. Here is a screenshot of what it looks like when Geode ask for a location: Getting started using GeodeYou should start by downloading the Geode add-on for Firefox and make sure your Wi-Fi is turned on. Then fire up your HTML editor and add this JavaScript to one of your pages: function geodeAsk() { if (navigator.geolocation) navigator.geolocation.getCurrentPosition(geoFound, geoNotFound); } function geoFound(pos) { var lat = pos.latitude; var lon = pos.longitude; alert(lat + ', ' + lon); } function geoNotFound() { alert('You must be on a wifi network for us to determine your location'); } // Ask the browser for its location geodeAsk(); Open the page in Firefox. Geode will now ask you if you want to share your location with the page. It's that simple. Geode then sends the latitude and longitude to the JavaScript callback method and you can now do whatever you want with it. If you want to retrieve the address based on the location, then you need to do a simple reverse GEO lookup. Comments About the Author: Mads Kristensen currently works as a Senior Developer at Traceworks located in Copenhagen, Denmark. Mads graduated from Copenhagen Technical Academy with a multimedia degree in 2003, but has been a professional developer since 2000. His main focus is on ASP.NET but is responsible for Winforms, Windows- and web services in his daily work as well. A true .NET developer with great passion for the simple solution. http://www.madskristensen.dk/ |
| DevWebProIN is an iEntry, Inc.® publication - All Rights Reserved Privacy Policy and Legal |