Skip to content

Instantly share code, notes, and snippets.

@ivarvong
Created August 10, 2010 04:58
Show Gist options
  • Save ivarvong/516706 to your computer and use it in GitHub Desktop.
Save ivarvong/516706 to your computer and use it in GitHub Desktop.
function getDirections(data) {
var responseBody = "";
requestStr = "/m/directions?dirflg=r&saddr=" + escape(data.from) + "&daddr=" + escape(data.to);
console.log(requestStr);
var client = http.createClient(80, 'www.google.com');
var request = client.request('GET', requestStr, {'host': 'www.google.com'});
request.end();
request.on('response', function (response) {
response.setEncoding('utf8');
response.on('data', function (chunk) {
responseBody += chunk;
});
response.on('end', function(data) {
//here i parse data, then i want to return it.
//but how do i get it to be the return value for getDirections() ?
//if i return here, it's just the return value of the anonymous function, right?
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment