We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 789837b commit e5b1364Copy full SHA for e5b1364
ch19/lib/geocode.js
@@ -0,0 +1,25 @@
1
+var http = require('http');
2
+
3
+module.exports = function(query, cb){
4
5
+ var options = {
6
+ hostname: 'maps.googleapis.com',
7
+ path: '/maps/api/geocode/json?address=' +
8
+ encodeURIComponent(query) + '&sensor=false',
9
+ };
10
11
+ http.request(options, function(res){
12
+ var data = '';
13
+ res.on('data', function(chunk){
14
+ data += chunk;
15
+ });
16
+ res.on('end', function(){
17
+ data = JSON.parse(data);
18
+ if(data.results.length){
19
+ cb(null, data.results[0].geometry.location);
20
+ } else {
21
+ cb("No results found.", null);
22
+ }
23
24
+ }).end();
25
+};
0 commit comments