Skip to content

Instantly share code, notes, and snippets.

@javieroot
Forked from manchoz/latlng.sh
Created May 17, 2017 17:45
Show Gist options
  • Save javieroot/9e51237b2e352e90ace0d485e9d2ca05 to your computer and use it in GitHub Desktop.
Save javieroot/9e51237b2e352e90ace0d485e9d2ca05 to your computer and use it in GitHub Desktop.
Address geocoding in Bash with Google Maps API
#!/bin/bash
# Quick and dirty geocoding with Google Maps API
MAPSAPIURL="http://maps.googleapis.com/maps/api/geocode/json"
[ -f latlng.txt ] && rm latlng.txt
[ -f results.json ] && rm results.json
while read line; do
# Get address from column 3 and 4 of a CSV file provided as argument and prepare the string address. YMMV.
address=`cut -d";" -f3-4 <<<$line | tr ';' '+' | tr ' ' '+'`
curl -G -s --data sensor=true --data-urlencode address=$address "$MAPSAPIURL" -o results.json
# Parse json with jshon (http://kmkeen.com/jshon/)
jshon -e results -a -e geometry -e location -e "lat" -u -p -e "lng" -u < results.json | paste -d, - - >> latlng.txt
sleep 1
done < $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment