The Geolocation API can be used to determine the user's location. This API is available over secure (HTTPS) connections and from localhost.
The following client-side code snippet retrieves the longitude and latitude of a user.
function success(position){
console.log(position.coords.latitude, position.coords.longitude);
}
function error(){
console.error("Geolocation not supported.");
}
navigator.geolocation.getCurrentPosition(success, error);
See the MDN documentation for more information.