I want to store latitude and longitude values in PHP variables, but unable to do so. Here is my code. Can someone help me out here why these values are not getting stored in php variables:
Code:
<!DOCTYPE html>
<html>
<body onload="getLocation()">
<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;
var lat = position.coords.latitude;
var longt = position.coords.longitude;
$.ajax({
type: 'POST',
data: { latitude : lat, longitude : longt },
});
}
</script>
<?php
$var = isset($_POST['latitude']);
$var1 = isset($_POST['longitude']);
echo $var;
echo $var1;
?>
</body>
</html>