I tried to take the geolocation coordinates and send them to the url
when the page is loaded.
I used the onload
function in javascript. When I run the js it works but it refreshes itself repeatedly.
<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.";
}
}
window.onload = getLocation;
function showPosition(position) {
window.location.href = "test_loc.php?latitude=" + position.coords.latitude +
"&longitude=" + position.coords.longitude;
}
</script>