Hello fellow coders,
I have to admit that my javascript knowledge is very rusty, I have gone through all the samples and even though I understand them to a certain degree, I am kind of wondering how I will go about writing them from scratch. But I will try.
Triggered by a question in the community I looked up a very small piece of code on W3schools.com and I tried to make it work in a pack. And I failed. I think it should be fairly simple, but javascript can be pretty tricky.
I hope that someone is willing to transpose the following to a working pack and leave a text copy of the pack-code in this thread. This bit of code works and returns the coordinates of your (device’s) location. Thank you in advance for your help!
Greetings, Joost
HTML/javascript:
<!DOCTYPE html>
<html>
<body>
<p>Click the button to get your coordinates.</p>
<button onclick="getLocation()">Try It</button>
<p id="demo"></p>
<script>
var x = document.getElementById("demo");
function getLocation() {
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>
</body>
</html>