2

I have found a code for autocomplete address on google side.. where they only link with one input box. But I want to link with multiple input box on same form.. please guide me. I am new in coding and at stackoverflow.So consider me a tyro at here.

 <head>
    <title>Place Autocomplete Address Form</title>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">

    <link type="text/css" rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500">

  </head>

  <body>
    <div id="locationField">
      <input id="autocomplete1" placeholder="Enter your address" onFocus="geolocate()" type="text">
      <input id="autocomplete2" placeholder="Enter your address" onFocus="geolocate()" type="text">
      <input id="autocomplete3" placeholder="Enter your address" onFocus="geolocate()" type="text">
    </div>



    <script>
      // This example displays an address form, using the autocomplete feature
      // of the Google Places API to help users fill in the information.

      // This example requires the Places library. Include the libraries=places
      // parameter when you first load the API. For example:
      // <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places">

      var placeSearch, autocomplete;


      function initAutocomplete() {
        // Create the autocomplete object, restricting the search to geographical
        // location types.
        autocomplete = new google.maps.places.Autocomplete(
            (document.getElementById('autocomplete1')),
            {types: ['geocode']});

      }


      // Bias the autocomplete object to the user's geographical location,
      // as supplied by the browser's 'navigator.geolocation' object.
      function geolocate() {
        if (navigator.geolocation) {
          navigator.geolocation.getCurrentPosition(function(position) {
            var geolocation = {
              lat: position.coords.latitude,
              lng: position.coords.longitude
            };
            var circle = new google.maps.Circle({
              center: geolocation,
              radius: position.coords.accuracy
            });
            autocomplete.setBounds(circle.getBounds());
          });
        }
      }
    </script>
    <script src="https://maps.googleapis.com/maps/api/js?key=*********************&libraries=places&callback=initAutocomplete" async defer></script>
  </body>
</html>

This is the sample code i have found on google.

Suman Mandal
  • 25
  • 1
  • 5
  • This will help you https://stackoverflow.com/questions/20416058/adding-multiple-instances-of-google-places-on-same-page – Madhusudan Oct 27 '18 at 04:43
  • possible duplicate of [Google Maps API autocomplete 2nd address fields on same page](https://stackoverflow.com/questions/33547312/google-maps-api-autocomplete-2nd-address-fields-on-same-page) – geocodezip Oct 27 '18 at 05:55

0 Answers0