title: Save current geolocation to variable
body: <p>How can I save lat and lng values to variables using HTML5 geolocation API?</p>
  
  <p>This is my code, copied from w3schools. How can I save coordinates to variables like <code>var x=   position.coords.latitude;</code>  and var <code>y= position.coords.longitude;</code>  instead of just showing the values like the code is doing right now? I am beginner with javascript so I don't know how to do this</p>
  
  <pre><code> &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;body&gt;
  &lt;p id="demo"&gt;Click the button to get your coordinates:&lt;/p&gt;
  &lt;button onclick="getLocation()"&gt;Try It&lt;/button&gt;
  &lt;script&gt;
  
  var x=document.getElementById("demo");
  window.onload = function getLocation()
    {
    if (navigator.geolocation)
      {
      navigator.geolocation.watchPosition(showPosition);
      }
    else{x.innerHTML="Geolocation is not supported by this browser.";}
    }
  function showPosition(position)
    {
    x.innerHTML="Latitude: " + position.coords.latitude + 
    "&lt;br /&gt;Longitude: " + position.coords.longitude;  
    }
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And in my application I need to send values of those variables to server every minute. Would it be better to do the geolocation with watchposition or execute function that does getcurrentposition every minute?</p>