I am developing a Contextual Search Engine in php. For that when an user types a query, I need her latlong and time. I am developing the search box in php. To get latlong I am using HTML 5 geolocation api. I have written following two files by taking idea from posts in stackoverflow.
order.php
<html>
<head>
<script type="text/javascript">
function getLocation(){
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){
var latitude=document.getElementById("latitude"),
longitude=document.getElementById("longitude");
latitude.value = position.coords.latitude;
longitude.value = position.coords.longitude;
}
</script>
</head>
<body onload="getLocation()">
<p id="demo"></p>
<form id="searchbox" action="process.php" method="get">
<input name="q" type="text" placeholder="Type here">
<input name="latitude" id="latitude" type="hidden">
<input name="longitude" id="longitude" type="hidden">
<input id="submit" type="submit" value="Search">
</form>
</body></html>
Another file is process.php
<html>
<body>
<form id="searchbox" action="process.php" method="post">
<input name="q" type="text" placeholder="Type here">
<input name="latitude" id="latitude" type="hidden" value="<?php $latitude=$_POST['latitude']; echo $latitude; ?>">
<input name="longitude" id="longitude" type="hidden" value="<?php $longitude=$_POST['longitude'];echo $longitude; ?>">
<input id="submit" type="submit" value="Search">
</form>
<?php $quantity=$_POST['quantity'];
$date = date('Y-m-d H:i:s');
$arr=explode(" ",$date);
$latitude=$_GET['latitude'];
$longitude=$_GET['longitude'];
echo "Latitude=". $latitude."Longitude=". $longitude." Time=".$arr[1]."<br>";
?>
</body>
</html>
The problem is that whenever I am submitting the form again from process.php the latitude and longitude values are getting reset. So how do I retain the value of them that I have got after landing on process.php so that they do not get reset even if I submit the form from process.php multiple times.
In this context I have seen other similar questions asked here and applied their solutions but none of them seems to be working. So please help. Thank you.