0

script

<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;
}
</script>

how to store position.coords.latitude and position.coords.longitude

to php variable for example

$latitude = "position.coords.latitude"; $longitude = "position.coords.longitude";

dndcorp
  • 1
  • 1
  • 1
    This doesn't make much sense, because php works on the server side and your javascript code is on the client side. Your question is a bit vague too, but something that might help you is to use ajax, with it you could send the value of this variable to a php page, and then on this page in php you would take the value of this variable and assign it to a php variable – Aks Jacoves Jun 12 '20 at 17:15
  • 1
    @AksJacoves is right. My advice would be the same. Don't mix client side and server side environments. Use AJAX to `POST` the variables, or use a `GET`, whichever you prefer and then you can use PHP to store the values. You can send an AJAX request to the same page as well, that's okay. – Martin Jun 12 '20 at 17:19

0 Answers0