input adresse ville automatique

"use strict";

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

  function initializeAutocomplete(id) {
        var element = document.getElementById(id);
        if (element) {
         var autocomplete = new google.maps.places.Autocomplete(element, { types: ['geocode'] });
         google.maps.event.addListener(autocomplete, 'place_changed', onPlaceChanged);
        }
      }

      // Injecte les données dans les champs du formulaire lorsqu'une adresse est sélectionnée
      function onPlaceChanged() {
        var place = this.getPlace();

        for (var i in place.address_components) {
          var component = place.address_components[i];
          for (var j in component.types) {
            var type_element = document.getElementById(component.types[j]);
            if (type_element) {
              type_element.value = component.long_name;
            }
          }
        }

        var longitude = document.getElementById("longitude");
        var latitude = document.getElementById("latitude");
        longitude.value = place.geometry.location.lng();
        latitude.value = place.geometry.location.lat();
      }

      // Initialisation du champs autocomplete
      google.maps.event.addDomListener(window, 'load', function() {
        initializeAutocomplete('user_input_autocomplete_address');
      });

0
0
John Glenn 100 points

                                    &lt;script src=&quot;https://maps.googleapis.com/maps/api/js?libraries=places&amp;key=votre_cle_api&quot; type=&quot;text/javascript&quot;&gt;

0
0
4
3

                                    &lt;!DOCTYPE html&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;Drawing Tools&lt;/title&gt;
    &lt;script src=&quot;https://polyfill.io/v3/polyfill.min.js?features=default&quot;&gt;&lt;/script&gt;
       &lt;script src=&quot;https://maps.googleapis.com/maps/api/js?key=AIzaSyB66GfQcN_lknxN1jwSMo12GPva-fOMPq8&amp;libraries=places&quot; type=&quot;text/javascript&quot;&gt;  &lt;/script&gt;

    &lt;!-- jsFiddle will insert css and js --&gt;
  &lt;/head&gt;
  &lt;body&gt;
     &lt;form&gt;
    &lt;div&gt;
      &lt;label&gt;Adresse&lt;/label&gt;
      &lt;input id=&quot;user_input_autocomplete_address&quot; placeholder=&quot;Votre adresse...&quot;&gt;
    &lt;/div&gt;

    &lt;div&gt;
      &lt;label&gt;Num&eacute;ro&lt;/label&gt;
      &lt;input id=&quot;street_number&quot; name=&quot;street_number&quot; disabled&gt;
    &lt;/div&gt;

    &lt;div&gt;
      &lt;label&gt;Route&lt;/label&gt;
      &lt;input id=&quot;route&quot; name=&quot;route&quot; disabled&gt;
    &lt;/div&gt;

    &lt;div&gt;
      &lt;label&gt;Code postal&lt;/label&gt;
      &lt;input id=&quot;postal_code&quot; name=&quot;postal_code&quot; disabled&gt;
    &lt;/div&gt;

    &lt;div&gt;
      &lt;label&gt;Ville&lt;/label&gt;
      &lt;input id=&quot;locality&quot; name=&quot;locality&quot; disabled&gt;
    &lt;/div&gt;

    &lt;div&gt;
      &lt;label&gt;Pays&lt;/label&gt;
      &lt;input id=&quot;country&quot; name=&quot;country&quot; disabled&gt;
    &lt;/div&gt;

    &lt;div&gt;
      &lt;label&gt;Latitude&lt;/label&gt;
      &lt;input id=&quot;latitude&quot; name=&quot;latitude&quot; disabled&gt;
    &lt;/div&gt;

    &lt;div&gt;
      &lt;label&gt;Longitude&lt;/label&gt;
      &lt;input id=&quot;longitude&quot; name=&quot;longitude&quot; disabled&gt;
    &lt;/div&gt;
  &lt;/form&gt;
  &lt;/body&gt;
&lt;/html&gt;

4 (3 Votes)
0
3.89
9

                                    &lt;!DOCTYPE html&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;Drawing Tools&lt;/title&gt;
    &lt;script src=&quot;https://polyfill.io/v3/polyfill.min.js?features=default&quot;&gt;&lt;/script&gt;
       &lt;script src=&quot;https://maps.googleapis.com/maps/api/js?key=AIzaSyB66GfQcN_lknxN1jwSMo12GPva-fOMPq8&amp;libraries=places&quot; type=&quot;text/javascript&quot;&gt;  &lt;/script&gt;

    &lt;!-- jsFiddle will insert css and js --&gt;
  &lt;/head&gt;
  &lt;body&gt;
     &lt;form&gt;
    &lt;div&gt;
      &lt;label&gt;Adresse&lt;/label&gt;
      &lt;input id=&quot;user_input_autocomplete_address&quot; placeholder=&quot;Votre adresse...&quot;&gt;
    &lt;/div&gt;

    &lt;div&gt;
      &lt;label&gt;Num&eacute;ro&lt;/label&gt;
      &lt;input id=&quot;street_number&quot; name=&quot;street_number&quot; disabled&gt;
    &lt;/div&gt;

    &lt;div&gt;
      &lt;label&gt;Route&lt;/label&gt;
      &lt;input id=&quot;route&quot; name=&quot;route&quot; disabled&gt;
    &lt;/div&gt;

    &lt;div&gt;
      &lt;label&gt;Code postal&lt;/label&gt;
      &lt;input id=&quot;postal_code&quot; name=&quot;postal_code&quot; disabled&gt;
    &lt;/div&gt;

    &lt;div&gt;
      &lt;label&gt;Ville&lt;/label&gt;
      &lt;input id=&quot;locality&quot; name=&quot;locality&quot; disabled&gt;
    &lt;/div&gt;

    &lt;div&gt;
      &lt;label&gt;Pays&lt;/label&gt;
      &lt;input id=&quot;country&quot; name=&quot;country&quot; disabled&gt;
    &lt;/div&gt;

    &lt;div&gt;
      &lt;label&gt;Latitude&lt;/label&gt;
      &lt;input id=&quot;latitude&quot; name=&quot;latitude&quot; disabled&gt;
    &lt;/div&gt;

    &lt;div&gt;
      &lt;label&gt;Longitude&lt;/label&gt;
      &lt;input id=&quot;longitude&quot; name=&quot;longitude&quot; disabled&gt;
    &lt;/div&gt;
  &lt;/form&gt;
  &lt;/body&gt;
&lt;/html&gt;

3.89 (9 Votes)
0
Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source