Skip to content

Instantly share code, notes, and snippets.

@mukhtyar
Forked from jsanz/README.md
Created July 6, 2016 18:08
Show Gist options
  • Save mukhtyar/8bd524876831c182e17dd349e2c28311 to your computer and use it in GitHub Desktop.
Save mukhtyar/8bd524876831c182e17dd349e2c28311 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;
// 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