Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

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');
      });
Source by www.sois-net.fr #
 
PREVIOUS NEXT
Tagged: #input #adresse #ville #automatique
ADD COMMENT
Topic
Name
7+2 =