title: Pass a user geolocation from client side to server side
body: <p>I am using a Google Geolocation API to obtain user location on the client side and trying to pass it to the server side for carrying out location queries.</p>
  
  <p>I am unable to obtain user location/pos variable (lat,lng) to the server side as this value is assigned to the input variable (location) only after the user accepts for using his current location, which is an instance following 'GET' method from the server and not vice versa. </p>
  
  <p>I would really appreciate some help in obtaining lat,lng from client side to server side. </p>
  
  <p>Below is the form that I used in geolocation.html</p>
  
  <pre><code>&lt;form id = "geolocation" action="" method="GET"&gt;
  &lt;input type="text" id = "location" name="location" value=""&gt;
  &lt;input type="submit" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Here's <a href="https://developers.google.com/maps/documentation/javascript/examples/map-geolocation" rel="nofollow">a link</a> to the Google geolocation API.
  Below is an excerpt from the code for obtaining user geolocation and assigning it to the HTML input field with id = location, so that I could use a GET method on the server side to obtain the geolocation. </p>
  
  <pre><code>if(navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(position) {
      var pos = new google.maps.LatLng(position.coords.latitude,
                                     position.coords.longitude);
  
      var infowindow = new google.maps.InfoWindow({
        map: map,
        position: pos,
        content: 'Location found using HTML5.'
    });
  
    // the below code has been inserted to assign a JS variable to HTML field called 'location'
  document.getElementById('location').value = pos
  </code></pre>