Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getZip(address) {
- if (address == '') {
- return 'ERROR: No address was provided';
- } else {
- var location = Maps.newGeocoder().geocoder.geocode(address);
- if (location.status == 'OK') return extractFromAddress(location.results[0].address_components, 'postal_code');
- else return 'ERROR: Something went wrong with Geocoder';
- }
- }
- function extractFromAddress(components, type) {
- for (var x = 0; x < components.length; x++) {
- for (var y = 0; y < components[x].types.length; y++) {
- if (components[x].types[y] == type) return components[x].long_name;
- }
- }
- }
Add Comment
Please, Sign In to add comment