I've been utilizing the Geolocation API to track a user's coordinates and then redirect them to the appropriate webpage based on their location. However, I'm having trouble setting up the if statement that will trigger the redirection. What specific variable should I use in the if statement to successfully direct the user to the correct page?
<button onclick="getLocation()">Get Location</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;
if (showPosition(latitude) > 34) {
console.log("It worked");
}
}
</script>