Guest User

Untitled

a guest
Mar 18th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. function getZip(address) {
  2. if (address == '') {
  3. return 'ERROR: No address was provided';
  4. } else {
  5. var location = Maps.newGeocoder().geocoder.geocode(address);
  6. if (location.status == 'OK') return extractFromAddress(location.results[0].address_components, 'postal_code');
  7. else return 'ERROR: Something went wrong with Geocoder';
  8. }
  9. }
  10.  
  11. function extractFromAddress(components, type) {
  12. for (var x = 0; x < components.length; x++) {
  13. for (var y = 0; y < components[x].types.length; y++) {
  14. if (components[x].types[y] == type) return components[x].long_name;
  15. }
  16. }
  17. }
Add Comment
Please, Sign In to add comment