Skip to content

Instantly share code, notes, and snippets.

@joyrexus
Created January 29, 2014 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joyrexus/8691369 to your computer and use it in GitHub Desktop.
Save joyrexus/8691369 to your computer and use it in GitHub Desktop.
Reverse geocoding CLI

Quick demo of how to use Google's reverse geocoding API.

Pass in a pair of latitude/longitude coordinates as args and the address is returned.

For example:

address.coffee 41.7840748 -87.6021859

... returns:

959-999 East 61st Street, Chicago, IL 60637, USA

See also Google's reverse geocoding service.

#!/usr/bin/env coffee
'''
Reverse geocoding demo: find address for given location coords.
'''
req = require 'request'
argv = require('optimist').argv
find = (lat, lng) ->
url = "https://maps.googleapis.com/maps/api/geocode/json?" \
+ "latlng=#{lat},#{lng}&sensor=false"
req url, (err, res, body) ->
data = JSON.parse(body)
console.log data.results[0].formatted_address
latitude = 41.7840748
longitude = -87.6021859
if argv._.length is 2
latitude = argv._[0]
longitude = argv._[1]
find latitude, longitude
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment