Created
July 7, 2011 03:06
-
-
Save anonymous/1068832 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // Server Code | |
| exports.actions = | |
| lookup: (coords_from_browser, cb) -> | |
| host = 'maps.googleapis.com' | |
| r = coords_from_browser.coords | |
| http = require('http') | |
| google = http.createClient(80, host) | |
| google.on 'error', (e) -> console.error "Unable to connect to #{host}" | |
| request = google.request 'GET', "/maps/api/geocode/json?sensor=true&latlng=#{r.latitude},#{r.longitude}" | |
| request.end() | |
| request.on 'error', (e) -> console.error "Unable to parse response from #{host}" | |
| request.on 'response', (response) => parseResponse(response, cb) | |
| parseResponse = (response, cb) -> # note: private methods are written outside of exports.actions | |
| output = '' | |
| response.setEncoding('utf8') | |
| response.on 'data', (chunk) -> output += chunk | |
| response.on 'end', -> | |
| j = JSON.parse(output) | |
| result = j.results[0] | |
| cb(result) | |
| // Client Code | |
| # Note: the SS.client.app.init() method automatically gets called once the socket is established and the session is ready | |
| exports.init = -> | |
| SS.client.geocode.determineLocation() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment