I have the following code:
<!DOCTYPE html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps JavaScript API Example: Extraction of Geocoding Data</title>
</head>
<body>
<script type="text/javascript">
var showPosition = function (position) {
document.write(position.coords.latitude + ',' + position.coords.longitude);
}
navigator.geolocation.getCurrentPosition(showPosition);
</script>
</body>
This little script outputs the user's location as in latitude and longitude. Instead of outputing this on the page I want to store the longitude and latitude in two separate variables so I can get the distance between the user's location and a given destination. I did some research and I understand that this can only be done using AJAX, however I have no idea how to do it.
That's when my question comes in, how do I store these values from JS in a PHP variable?
Also, if there's any way that's faster to calculate the distance in kms between the user's location and a given destination, I am open to suggestions.
Thank you!