Tuesday, June 02, 2009

Geo Location in browser

HTML 5 will support geo locations. It is not implemented yet in the full form, but something you can get already right now. Here is a useful table for the current state of geo location support:

Web BrowserGeolocation API support
Mozilla Firefoxsupported in Firefox 3.5 and later versions.
ChromeSupports thru Google Gears Geolocation API
OperaSupported in nightly builds - download from this page
SafariSupport is coming soon in the IPhone’s Safari browser.
Internet ExplorerAn experimental support available from IE8.

There is also one practical trick we've used in some applications (e.g. Geo search) If you are loading Google Ajax API (just a load - do not need to use it :), Google automatically populates a google.loader.ClientLocation object. And you can get from it the geo locations for the user:

<script type="text/javascript" src="http://www.google.com/jsapi?key=your_key"></script>

and some like that in your JavaScript code:

lat = google.loader.ClientLocation.latitude;
lng = google.loader.ClientLocation.longitude;
city = google.loader.ClientLocation.address.city;
region = google.loader.ClientLocation.address.region;
country = google.loader.ClientLocation.address.country;
code = google.loader.ClientLocation.address.country_code;

No comments: