View the geolocation.js source to see how this is done.