title: How to get latitude and longitude from an input address
body: <p>Hi I have an address field taking address from france only.
  I want that address to be stored with longitude and latitude in my database.. Is there a way to do that.. I'm trying several codes but none of them are working.</p>
  
  <p>here is my code</p>
  
  <pre><code>&lt;form id="contact" action="send.php" method="post"&gt;&lt;br&gt; 
      &lt;h2&gt;Formulaire de contact&lt;/h2&gt;
      &lt;div id="locationField" required&gt;
          &lt;input id="autocomplete" placeholder="Adresse"
                 onFocus="geolocate()" type="text" name="address" required="required"&gt;&lt;/input&gt;
      &lt;/div&gt;&lt;br&gt;
      &lt;input type="hidden" name="latitude" id="at" placeholder="Latitude" class="form-control" required="required"/&gt;
      &lt;input type="hidden" name="longitude" id="lng" placeholder="Longitude" class="form-control" required="required"/&gt;
      &lt;input type="submit" name="submit" value="submit" class="button"/&gt;
  
      &lt;script&gt;
          function initAutocomplete() {
              autocomplete = new
                      google.maps.places.Autocomplete(
                              /** @type {!HTMLInputElement}  
  
                               */(document.getElementById('autocomplete')),
                              {types: ['geocode'], componentRestrictions: {country: 'fr'}});
  
              autocomplete.addListener('place_changed', fillInAddress);
          }
  
          document.getElementById('latitude').value = place.geometry.location.lat();
          document.getElementById('longitude').value = place.geometry.location.lng();
      &lt;/script&gt;
  
      &lt;script src="https://maps.googleapis.com/maps/api/js?input=Paris&amp;types=geocode&amp;key=xxxxxxxxxxxxxxxxxxxxxx&amp;libraries=places&amp;callback=initAutocomplete"
      async defer&gt;&lt;/script&gt;
  &lt;/form&gt;
  
  &lt;?php
  if (isset($_POST["submit"])) {
      $servername = "localhost";
      $username = "root";
      $password = "";
      $dbname = "web_contact";
  
      // Create connection
      $conn = new mysqli($servername, $username, $password, $dbname);
  
      if ($conn-&gt;connect_error) {
          die("Connection failed: " . $conn-&gt;connect_error);
      }
  
      $sql = "INSERT INTO customer1(address,latitude,longitude) 
  
    values('" . $_POST["address"] . "','" . $_POST["latitude"] . "','" . $_POST["longitude"] . "')";
  
      if (mysqli_query($conn, $sql)) {
          echo "New record created successfully";
      } else {
          echo "Error: " . $sql . "" . mysqli_error($conn);
      }
  }
  </code></pre>