Checking for Support with User's browser

Before we attempt to use geolocation for determining the location of the Internet device, we should ensure that our visitor’s browser supports the GeoLocation feature natively. If it does, call the getCurrentPosition
method:

if (navigator && navigator.geolocation) {
navigator.geolocation.getCurrentPosition(geo_success, geo_error);
} else {
error('GeoLocation is not supported.');
}

Since this method executes asynchronously, pass it two callback functions: geo_success and geo_error. The error callback is passed a position error object that contains a code and a message property. The code can be one of the following:

0 - Unknown
1 - Permission Denied
2 - Position Unavailable
3 - Timeout

The success callback is passed a position object that contains a coordinates object and a timestamp.
Related Tutorial