HTML5 Geolocation – Google Map with Modernizr

Written on July 4th, 2010 by Thor2 shouts

HTML5 defines a very handy function, which is geolocation. Basically, this function will try to locate user’s location. But at the moment, not every browser supports this function. We need to implement some tedious conditions to check whether the browser supports Geolocation or not. Luckily, there is an open source javascript library, Modernizr. Using modernizr is simple, just import a script and use it. For example, if I want to check the browser whether Geolocation is supported or not, I just write the following code


if (Modernizr.geolocation){
//...Your logic here
}

Here, I wrote a simple html page that locate your location using Geolocation and show it on the Google map.

http://just-thor.com/sample-works/geolocation.html

Happy coding.

Share and Enjoy:
  • Print
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks
  • DZone
  • LinkedIn
  • Live
  • Reddit
Filed under Programming Tags:, ,

2 Comments to “HTML5 Geolocation – Google Map with Modernizr”

  • Wow, thats neat…I didn’t know it can be so easy. Does it also provide location information in text, as in city state etc?

  • Thor says:

    Hi,Modernizr is used to detect whether such functions like geolocation or local storage are supported by the browser or not…We can always use Google Geocoding Service to translate latitude and longitude into address

Leave a Reply

(required)

(required)