Skip to content

Instantly share code, notes, and snippets.

@braicauc
Last active October 24, 2016 11:13
Show Gist options
  • Save braicauc/d117b518045261d589d93a27f2dda543 to your computer and use it in GitHub Desktop.
Save braicauc/d117b518045261d589d93a27f2dda543 to your computer and use it in GitHub Desktop.
Geolocation script ... does not work in chrome without SSL
function showPosition(position) {
document.write('Latitude: '+position.coords.latitude+'Longitude: '+position.coords.longitude);
}
function showError(error) {
switch(error.code) {
case error.PERMISSION_DENIED:
alert("User denied the request for Geolocation.");
break;
case error.POSITION_UNAVAILABLE:
alert("Location information is unavailable.");
break;
case error.TIMEOUT:
alert("The request to get user location timed out.");
break;
case error.UNKNOWN_ERROR:
alert("An unknown error occurred.");
break;
}
}
if (navigator.geolocation) {
var optn = {
enableHighAccuracy : true,
timeout : Infinity,
maximumAge : 0
};
navigator.geolocation.getCurrentPosition(showPosition, showError, optn);
} else {
alert('Geolocation is not supported in your browser');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment