title: How to get geolocation and return value in html form
body: <p>How do I get Geolocation and return it into a form when I click on a button.</p>
  
  <p>So when  click the Geolocation get my location and then return the output in the from so I can use it later on.
  <a href="http://jsfiddle.net/Mikki10/as3mg177/1/" rel="nofollow">http://jsfiddle.net/Mikki10/as3mg177/1/</a></p>
  
  <p>Geolocation</p>
  
  <pre><code>&lt;html&gt;   
  &lt;body&gt;
      &lt;p&gt;Click the button to get your coordinates.&lt;/p&gt;
      &lt;button onclick="getLocation()"&gt;Get geolocation and put into from&lt;/button&gt;
      &lt;p id="demo"&gt;&lt;/p&gt;
      &lt;script&gt;
          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 +
                  "&lt;br&gt;Longitude: " + position.coords.longitude;
          }
      &lt;/script&gt;
      &lt;form action="geo/ruteplanlag.php" method="get"&gt;
          &lt;input style="width: 98%; margin: 20px auto; text-align: center;" name="startadr" type="text" value="(Custom value like Orlando or geolocation) " /&gt;
          &lt;input style="width: 98%; margin: 20px auto; text-align: center;" name="slutadr" type="text" value="Miami" /&gt;
          &lt;div class="buttonHolder"&gt;
              &lt;input type="submit" value="Start ruteplanlægning"&gt;
          &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>