Last active
June 29, 2017 17:14
-
-
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
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
// 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