Skip to content

Instantly share code, notes, and snippets.

@alexfu
Created November 1, 2018 13:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alexfu/caef5ff703471fc553884a87f37d5c70 to your computer and use it in GitHub Desktop.
Save alexfu/caef5ff703471fc553884a87f37d5c70 to your computer and use it in GitHub Desktop.
Bash script that geocodes a location.
#!/bin/bash
BASE_URL="https://maps.googleapis.com/maps/api/geocode/json"
API_KEY="" # Obtain an API key from https://developers.google.com/maps/documentation/geocoding/get-api-key
ADDRESS=$1
curl -s -G $BASE_URL --data-urlencode "address=$1" --data-urlencode "key=$API_KEY" | jq '.results[] | { name: .formatted_address, latLng: "\(.geometry.location.lat),\(.geometry.location.lng)" }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment