-
-
Save grantmichaels/2689724 to your computer and use it in GitHub Desktop.
node.js google reverse geocode proxy
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
var http = require('http'), | |
q = require('querystring') | |
http.createServer(function (req, res) { | |
//create the geo long/lat path | |
var url=["/maps/geo?q=" | |
,q.parse(req.url)["long"] | |
,"," | |
,q.parse(req.url)["lat"] | |
,"&output=json&sensor=false"].join(""), | |
//create the options to pass into the get request | |
options={host:"maps.google.com" | |
,path:url}; | |
//a little lightweight logging to watch requests | |
console.log("url:",options.host+options.path); | |
console.log("requrl:",req.url); | |
//make the request server side | |
http.get(options,function(response){ | |
//console.log("hi",response); | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
var pageData = ""; | |
response.setEncoding('utf8'); | |
//stream the data into the response | |
response.on('data', function (chunk) { | |
pageData += chunk; | |
}); | |
//write the data at the end | |
response.on('end', function(){ | |
res.write(pageData); | |
res.end(); | |
}); | |
}); | |
}).listen(80); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment