I'm trying to get coords through html's geolocation automatically on page load, but it isn't working.
<body >
<p id="demo">hi</p>
</body>
<script>
$(document).ready(function () {
var x = document.getElementById("demo");
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
});
</script>
Any help is much appreciated.