Skip to content

Instantly share code, notes, and snippets.

@burritojustice
Forked from jsanz/README.md
Last active August 31, 2016 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save burritojustice/ad9a301e8dabb374e7424444fe1650eb to your computer and use it in GitHub Desktop.
Save burritojustice/ad9a301e8dabb374e7424444fe1650eb to your computer and use it in GitHub Desktop.
Geocode with Mapzen search and Google Spreadsheets

How to set up a quick geocoding system on google spreadsheets.

  1. Create a new spreadsheet
  2. Open the Scripts editor and paste the script attached
  3. Use on your spreadsheet this new formula
=searchMapzen(place_cell,mapzen_api_key)

So you need to register at Mapzen developers site and get your own search API Key. Take this as an exercise, you can interact with the search API in many ways.

Enjoy!

function searchMapzen(place,api_key){
// return nothing if no data
if (!place) return null;
Utilities.sleep(Math.random() * 1000);
// set up url and fetch info
var url = "https://search.mapzen.com/v1/search?api_key=" + api_key + "&text=" + encodeURIComponent(place);
var response = UrlFetchApp.fetch(url,{
"headers" : {
"Content-Type":"application/json",
"Accept" :"application/json"
}
});
// parse results and return the first one
var results = JSON.parse(response.getContentText());
if (results.features && results.features.length >= 1){
var first = results.features[0];
return [
[
first.properties.label,
first.geometry.coordinates[0],
first.geometry.coordinates[1],
first.properties.confidence
]
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment