Last active
October 24, 2016 11:13
-
-
Save braicauc/d117b518045261d589d93a27f2dda543 to your computer and use it in GitHub Desktop.
Geolocation script ... does not work in chrome without SSL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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