This shows how to use various APIs to try to find the location of the user of your website. It tries several techniques to find the user's location, starting with the most precise and then moving onto less precise methods.
First it will try to use the W3C geolocation standard. At time of writing this is only supported by Chrome and FireFox (although it also works if the Google toolbar has been installed in IE), but appears to be very accurate.
Next it will try to use the Google Gears geolocation API. This can be used by any supporting browser that has Google Gears installed. Again this seems to be very accurate.
If none of these work, it will attempt to use the Google loader API. This should work in any browser but appears to be based on the user's IP address, so accuracy is pretty hit and miss (if it works at all).
Finally, the location will be guessed based on the user's locale. This is pretty inaccurate and may be completely wrong, if the user has set their locale to something not related to their actual location. My mapping of locales to locations is not complete so this method also may not work at all.