Geolocation
Geolocation API uses common sources to provide location information that includes Global Positioning System (GPS) or location information inferred from network signals, such as Internet Protocol (IP) addresses or Media Access Control (MAC) addresses. You can include Geolocation API in your Web page by using the NavigatorGeolocation interface, which provides an object of the Geolocation interface. The Geolocation interface provides the getCurrentPosition() method to obtain the current location of the device, as shown in the following code snippet:
navigator.geolocation.getCurrentPosition(gotPosition,errorGettingPosition, {'enableHighAccuracy':true,'timeout':10000,'maximumAge':0});
The Geolocation interface also provides the watchPosition() method to monitor the position of the device and invoke the appropriate callback method when the position changes, as shown in the following code snippet:
var watchid = navigator.geolocation.watchPosition( gotPosition, errorGettingPosition, {'enableHighAccuracy':true,'timeout':10000,'maximumAge':20000});
Click here for demos to see how to Geolocation API:
demo