Apparently the problem is because Chrome blocks the user's location queries that are not safe, so I posted a question in Meta SE.
In stack snippet I am testing the code of link
When I run it, the stack snippet console shows me
Warning: ERROR (1): User denied Geolocation
In my browser settings I have given permission to show my location to es.stackoverflow.com. What more do I need?
var options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
};
function success(pos) {
var crd = pos.coords;
console.log('Your current position is:');
console.log('Latitude : ' + crd.latitude);
console.log('Longitude: ' + crd.longitude);
console.log('More or less ' + crd.accuracy + ' meters.');
};
function error(err) {
console.warn('ERROR(' + err.code + '): ' + err.message);
};
navigator.geolocation.getCurrentPosition(success, error, options);