Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

get zipcode from google places autocomplete

function initialize() {
  var input = document.getElementById('id_address');
  var options = {
    types: ['address'],
    componentRestrictions: {
      country: 'us'
    }
  };
  autocomplete = new google.maps.places.Autocomplete(input, options);
  google.maps.event.addListener(autocomplete, 'place_changed', function() {
    var place = autocomplete.getPlace();
    for (var i = 0; i < place.address_components.length; i++) {
      for (var j = 0; j < place.address_components[i].types.length; j++) {
        if (place.address_components[i].types[j] == "postal_code") {
          document.getElementById('postal_code').innerHTML = place.address_components[i].long_name;

        }
      }
    }
  })
}
google.maps.event.addDomListener(window, "load", initialize);
Comment

PREVIOUS NEXT
Code Example
Javascript :: java script how to not allow soace 
Javascript :: resize array javascript 
Javascript :: find common characters in two strings javascript 
Javascript :: mongoose search by name 
Javascript :: axios error message 
Javascript :: react hook form validation 
Javascript :: jquery add option if not exist 
Javascript :: if clicked anything 
Javascript :: Javascript load at Window loading time 
Javascript :: jquery 
Javascript :: how to print in a same line in javascript 
Javascript :: add class with jquery 
Javascript :: brwoser prompt before reload 
Javascript :: ho to loop trough an array of objects 
Javascript :: lifecycle state: defunct, not mounted 
Javascript :: document.queryselectorall extract all href element 
Javascript :: javascript global object 
Javascript :: jquery load 
Javascript :: regex.match 
Javascript :: sequelize update sql 
Javascript :: dropdown search field in react native 
Javascript :: truncate string in javascript 
Javascript :: react native "modalize" above bottom navigation 
Javascript :: javascript capitalize all letters 
Javascript :: puppeteer wait for page loadjavascript 
Javascript :: javascript shift everything in array to the right 
Javascript :: cypress multiple true 
Javascript :: variable used in a function can be used in another function js 
Javascript :: insert element at beginning of array javascript 
Javascript :: jest run specific test 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =