Skip to content

Instantly share code, notes, and snippets.

@jsanz
Last active April 19, 2017 15:21
Show Gist options
  • Save jsanz/8d9f72a21f69b1e03b72 to your computer and use it in GitHub Desktop.
Save jsanz/8d9f72a21f69b1e03b72 to your computer and use it in GitHub Desktop.
CLI geocode with the Mapzen Search API bash

Small utility to geocode using the nice Mapzen Search geocoder.

This tool simply encodes the first argument and passes it to curl. The result is passed to jq to extract the first result and then using json2csv converts the array result into a couple of coordinates.

So using it is as easy as:

% geocode.sh "valencia"
"Valencia, Municipio Valencia, Venezuela",-68.00765,10.16202,0.947
% geocode.sh "valencia,spain"
"Valencia, Província de València, Spain",-0.37739,39.46975,0.956

Results will be:

  • Complete name of the place
  • Latitude
  • Longitude
  • Confidence of the result

Feel free to adapt, extend to your requirements.

<3

#!/bin/sh
MAPZEN_API="YOUR_API_KEY"
TEXT=`python -c "import urllib, sys; print urllib.quote('$1')"`
curl -s "https://search.mapzen.com/v1/search?text=$TEXT&api_key=$MAPZEN_API" | \
jq -c '.features[0] | [.properties.label,.geometry.coordinates[0],.geometry.coordinates[1],.properties.confidence]' | \
json2csv -L -n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment