Skip to content

Instantly share code, notes, and snippets.

@superstrong
Last active June 29, 2017 17:14
Show Gist options
  • Save superstrong/0fb84ac2d298a2ac545d to your computer and use it in GitHub Desktop.
Save superstrong/0fb84ac2d298a2ac545d to your computer and use it in GitHub Desktop.
A Google Script that transforms a zip code into city, state zip via zippopotam.us
// Example use in a cell: "=map(90210)" (without quotes)
// Example output: "Beverly Hills, CA 90210"
function map(zip_code) {
// Make HTTP Request
var url = 'http://api.zippopotam.us/us/' + zip_code;
var response = UrlFetchApp.fetch(url);
var json = response.getContentText();
var data = JSON.parse(json);
places = data['places'][0];
city_output = places['place name'];
state_output = places['state abbreviation'];
location = city_output + ', ' + state_output + ' ' + zip_code;
return location;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment