-
-
Save javieroot/9e51237b2e352e90ace0d485e9d2ca05 to your computer and use it in GitHub Desktop.
Address geocoding in Bash with Google Maps API
This file contains 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
#!/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