Created
January 1, 2010 20:41
-
-
Save r/267244 to your computer and use it in GitHub Desktop.
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
function xmlcurl { | |
curl -s $1 | tidy -xml -i -w 0 -q | |
} | |
YAHOO_API_ENDPOINT="http://where.yahooapis.com/v1" | |
# get this APP_ID from http://developer.yahoo.com/geo/geoplanet/ | |
YAHOO_APP_ID=FILL YOUR APP ID HERE | |
# lookup a string and find a matching WOEID | |
function woeid_search { | |
LOC=$(echo -n "$1" | perl -pe's/([^-_.~A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg'); | |
xmlcurl "$YAHOO_API_ENDPOINT/places.q('$LOC')?appid=$YAHOO_APP_ID" | |
} | |
# lookup a WOEID and return data about it | |
function woeid_lookup { | |
xmlcurl "$YAHOO_API_ENDPOINT/place/$1?appid=$YAHOO_APP_ID" | |
} | |
# given a WOEID, return the parent WOEID | |
function woeid_parent { | |
xmlcurl "$YAHOO_API_ENDPOINT/place/$1/parent?select=long&appid=$YAHOO_APP_ID" | |
} | |
# get this MAPS_KEY from http://code.google.com/apis/maps/ | |
GOOGLE_MAPS_KEY=FILL YOUR MAPS KEY HERE | |
# given a lat and a long, return the google reverse geocode information about | |
# it. this optionally takes a third parameter of "json" which then fetches the | |
# JSON representation | |
function google_reverse_geocode { | |
if [ "$3" == 'json' ]; then | |
OUTPUTTYPE="json" | |
COMMAND="curl" | |
else | |
OUTPUTTYPE="xml" | |
COMMAND="xmlcurl" | |
fi | |
$COMMAND "http://maps.google.com/maps/geo?q=$1,$2&output=$OUTPUTTYPE&sensor=false&key=$GOOGLE_MAPS_KEY" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment