Guest User

Untitled

a guest
Jun 18th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. const request = require('request');
  2. const yargs = require('yargs');
  3.  
  4. const argv = yargs
  5. .options({
  6. a: {
  7. demand: true,
  8. alias: 'address',
  9. describe: 'Address to fetch weather for',
  10. string: true
  11. }
  12. })
  13. .help()
  14. .alias('help', 'h')
  15. .argv;
  16.  
  17. var encodedAddress = encodeURIComponent(argv.address);
  18.  
  19. request({
  20. url: `https://maps.googleapis.com/maps/api/geocode/json?address=${encodedAddress}`,
  21. json: true
  22. }, (error, response, body) => {
  23. if (error) {
  24. console.log('unable to connect to google servers');
  25. } else if (body.status === 'ZERO_RESULTS') {
  26. console.log('unable to find that address');
  27. } else if (body.status === 'OK') {
  28. console.log(`Address: ${body.results[0].formatted_address}`);
  29. console.log(`Latitude: ${body.results[0].geometry.location.lat}`);
  30. console.log(`Longitude: ${body.results[0].geometry.location.lng}`);
  31. }
  32. });
Add Comment
Please, Sign In to add comment