// 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()