-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgmaps.js
More file actions
90 lines (81 loc) · 2.72 KB
/
gmaps.js
File metadata and controls
90 lines (81 loc) · 2.72 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const request = require('request');
var getWeather = (latitude,longitude) => {
return new Promise((resolve,reject)=> {
request({
url:'https://api.darksky.net/forecast/8f0e1d9e31e8d062740bc53fbd75665c/' + latitude + ',' + longitude,
json: true
}, (error,response,body) => {
if (error) {
reject('Cannot connect to darksky')
// console.log('Cannot connect to Google Maps');
} else if (body.code == '400') {
reject('Cannot find requested Address');
console.log(request.url);
// console.log('Cannot find requested Address');
} else if (body.timezone) {
resolve({
// address: body.results[0].formatted_address,
// type: body.results[0].types[0]
timezone: body.timezone,
temperature: body.currently.temperature,
humidity : body.currently.humidity,
ozone : body.currently.ozone,
status : body.currently.summary
});
// console.log(JSON.stringify(body.results[0].geometry.location,undefined,2));
// console.log(`Your requested revenue: ${argv.a}`);
// console.log(`Adress: ${body.results[0].formatted_address}`)
// console.log(`Type: ${body.results[0].types[0]}`)
};
});
})
};
var getAddress = (address) => {
return new Promise((resolve,reject)=> {
request({
url: 'http://maps.googleapis.com/maps/api/geocode/json' +
'?address=' + encodeURIComponent(address),
json: true
}, (error, response, body) => {
if (error) {
reject('Cannot connect to Google Maps');
//console.log('Cannot connect to Google Maps');
} else if (body.status === 'ZERO_RESULTS') {
reject('Cannot find requested address');
//console.log('Cannot find requested address');
} else if (body.status === 'OK') {
resolve({
lat: body.results[0].geometry.location.lat,
long: body.results[0].geometry.location.lng
});
}
});
})
};
var getImage = (keyword) => {
return new Promise((resolve,reject)=> {
request({
url: 'https://pixabay.com/api/?key=7246674-b37ac3e55b379cef1f626bb09&q=' + keyword,
json: true
}, (error, response, body) => {
if (error) {
reject('Cannot connect to Google Maps');
//console.log('Cannot connect to Google Maps');
} else if (body.status === 'ZERO_RESULTS') {
reject('Cannot find requested address');
//console.log('Cannot find requested address');
} else if (body.status === 'OK') {
resolve({
// lat: body.results[0].geometry.location.lat,
// long: body.results[0].geometry.location.lng
img: hits.largeImageURL
});
}
});
})
};
module.exports = {
getWeather,
getAddress,
getImage
};