Geolocation into HTML 5

According to the W3C specification, geolocation is an "… API that provides scripted access to geographical location information associated with the hosting device." Because geolocation is a built-in API, all you need to get started is a browser that supports it. At the time of this writing, Internet Explorer 9 (including Internet Explorer 9 on Windows Phone 7.5,  code-named "Mango"),as well as the current versions of Chrome, Firefox, Safari and Opera, all support geolocation, so the specification is not only broadly supported, but probably available to a large segment of your user base.

The Geolocation API lives in the global "navigator" object in JavaScript (window.navigator.geolocation). It provides two ways to work with location services: one-shot position requests and repeated position updates. For one-shot requests, use the getCurrentPosition method, like so:

  1. navigator.geolocation.getCurrentPosition(function(position) {
  2.        var coordinates = position.coords;
  3.        console.log("Your latitude: " + coordinates.latitude + " and longitude:
  4.          " + coordinates.longitude + " (Accuracy of:
  5.          " + coordinates.accuracy + " meters)");
  6. }, errorHandler, { maximumAge: 100, timeout: 6000, enableHighAccuracy: true});

Read full article here