HTML5 supports geolocation with its Geolocation API. The geolocation in HTML5 centered on global object called
Here’s the code to display geolocation:
However, the geolocation is only supported in modern browser and the code above doesn’t check for browser’s geolocation support. That being said, there is no error handling if browser doesn’t support geolocation. To implement error handling, we can use Modernizr.
gears_init.js – can be downloaded from http://code.google.com/apis/gears/gears_init.js
Geo.JS API usage is similar to W3C Geolocation API, it’s written in aligned to W3C standard. The advantage compare to W3C Geolocation API is that Geo.JS supports error handling. Here’s my code:
geo_position_js.init(), we initiated the API. The code will also return
false if geolocation is not supported by the browser.