-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
35 lines (29 loc) · 976 Bytes
/
app.js
File metadata and controls
35 lines (29 loc) · 976 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const request = require('request');
const yargs = require('yargs');
const argv = yargs
.options({
a: {
demand: true,
alias: 'address',
describe: 'Address to fetch weather for',
string: true
}
})
.help()
.alias('help', 'h')
.argv;
var encodedAddress = encodeURIComponent(argv.address);//to encode the string
request({
url: `http://maps.googleapis.com/maps/api/geocode/json?address=${encodedAddress}`,
json: true
}, (error, response, body) => {
if(error){
console.log('Unable to connect to Google Server');
} else if(body.status === 'ZERO_RESULTS'){
console.log('Unable to find this address');
}else if(body.status === 'OK'){
console.log(`Address: ${body.results[0].formatted_address}`);
console.log(`Longitute: ${body.results[0].geometry.location.lng}`);
console.log(`Latitude: ${body.results[0].geometry.location.lat}`);
}
});