0

I am not even sure that this is possible, but here it is.

I want user to fill the form, and once he goes to the field

<label for="pos">My possition</label>          
<input type="email" id="pos" name="clients_position">

I want to request his position and receive from him a Google Maps coordinate in such format "40.417035, -3.685389", ideally I want them automatically added to the input field.

Just did first basic course on JS in T3H and I am totally lost. HTML and CSS is a walk in a park compared to this, so I need some directions.

vlad
  • 965
  • 2
  • 9
  • 16
  • guess he is searching for sth like this: https://stackoverflow.com/questions/35600754/how-to-use-address-instead-of-lat-long-in-google-map-api/35601336#35601336 – el solo lobo Mar 20 '16 at 19:35

1 Answers1

1

the simplest way for obtain the coordinates of an user is use html 5 geolocation this is a sample

    <!DOCTYPE html>
    <html>
      <body>

      <p>Click the button to get  the coordinates.</p>

      <button onclick="getLocation()">Get coordinates </button>

      <p id="my_sample"></p>

      <script>
      var x = document.getElementById("my_sample");

      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>

      </body>
    </html>
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107