Last active
November 14, 2017 23:19
-
-
Save lyatziv/a3a65d5e6c61ff45dd56e6b59a5d1a52 to your computer and use it in GitHub Desktop.
ziptastic or zippopotam.us alternative
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fetch('https://maps.googleapis.com/maps/api/geocode/json?address=10030®ion=US', { | |
method: 'get' | |
}).then((response) => response.json()) | |
.then((response) => { | |
let address = response.results[0].address_components.reduce((comps, comp) => { | |
let attr = comp.types[0]; | |
attr = (attr === 'administrative_area_level_2') ? 'county' : attr; | |
attr = (attr === 'administrative_area_level_1') ? 'state' : attr; | |
comps[attr + '_long'] = comp.long_name; | |
comps[attr + '_short'] = comp.short_name; | |
return comps; | |
}, {}); | |
console.log('address ', address); | |
}).catch(function (err) { | |
console.log("Error: ", err); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment