After searching for the address in the "search" field of the map and to bring the address, how to automatically fill in the address of the form below?

0
<input id="pac-input" class="controls" type="text" placeholder="Search Box">
<div id="map" style="height:300px;"></div>
<script>

  function initAutocomplete() {
  var geocoder = new google.maps.Geocoder;
    var map = new google.maps.Map(document.getElementById('map'), {
      center: {lat:-22.330953, lng: -49.070956},
      zoom: 17,
      mapTypeId: 'roadmap'
    });

    // Create the search box and link it to the UI element.
    var input = document.getElementById('pac-input');
    var searchBox = new google.maps.places.SearchBox(input);
    map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);

    // Bias the SearchBox results towards current map's viewport.
    map.addListener('bounds_changed', function() {
      searchBox.setBounds(map.getBounds());
    });

    var markers = [];
    // Listen for the event fired when the user selects a prediction and retrieve
    // more details for that place.
    searchBox.addListener('places_changed', function() {
      var places = searchBox.getPlaces();

      if (places.length == 0) {
        return;
      }

      // Clear out the old markers.
      markers.forEach(function(marker) {
        marker.setMap(null);
      });
      markers = [];

      // For each place, get the icon, name and location.
      var bounds = new google.maps.LatLngBounds();
      places.forEach(function(place) {
        if (!place.geometry) {
          console.log("Returned place contains no geometry");
          return;
        }
        var icon = {
          url: place.icon,
          size: new google.maps.Size(71, 71),
          origin: new google.maps.Point(0, 0),
          anchor: new google.maps.Point(17, 34),
          scaledSize: new google.maps.Size(25, 25)
        };

        // Create a marker for each place.
       markers.push(new google.maps.Marker({
          map: map,
          icon: icon,
          title: place.name,
          position: place.geometry.location
        }));

        if (place.geometry.viewport) {
          // Only geocodes have viewport.
          bounds.union(place.geometry.viewport);
        } else {
          bounds.extend(place.geometry.location);
        }
      });
      map.fitBounds(bounds);
    });

  }

</script>


<form method="POST" action="#" >
<table id = "todoform">
<thead>
    <tr>
  <th colspan="2">Cadastro de Alunos</th>
</tr>
</thead>
<tbody>
<tr>
  <td><input type="hidden" name="id"</td></tr>
 <tr>
 <td><label>Nome:</label></td>
 <td><input type="text" name="nome" </td></tr>

 <tr>

<td><label>CPF:<label></td>

  <td><input type="text" name="cpf" size="10"></td></tr>       
 <tr>
 <td><label>e-Mail:</label></td>
 <td><input type="text" name="email" size="10"></td></tr>      

<tr>
 <td><label>Celular:</label></td>
 <td><input type="text" name="celular" size="10"></td></tr>   
<tr>
 <td><label>Logradouro:</label></td>
 <td><input type="text" id = "logr" name="logradouro" size="10" ></td></tr>          
 <tr>
 <td><label>Número:</label></td>
 <td><input type="text" id = "num" name="numero" size="10"></td></tr>   
<tr>
 <td><label>Bairro:</label></td>
 <td><input type="text" id = "bairro" name="bairro" size="10"></td></tr>           
 <tr>
 <td><label>Cidade:</label></td>
 <td><input type="text" id = "cidade" name="cidade" size="10" ></td></tr>      
 <tr>
 <td><label>Latitude:</label></td>
 <td><input type="text"  id = "lat" name="latitude" size="10" ></td></tr>      
<tr>
 <td><label>Longitude:</label></td>
 <td><input type="text" id = "lon" name="longitude" size="10" ></td></tr>      
<tr></tr> 
<tr></tr> 
 </tbody>
 <tfoot align = "center">
 <tr>
  <td colspan = "2">
  <input type="submit" name="salvar" value="Salvar" class="botao"/> 

     </td></tr>

 </tfoot>
 </table>

    
asked by anonymous 11.06.2018 / 16:00

0 answers