1
0
This commit is contained in:
Jason Williams
2019-09-29 12:36:49 -06:00
parent ef64250820
commit 5ffdfbbb98
3 changed files with 11 additions and 11 deletions

View File

@@ -3,13 +3,13 @@ const request = require('request')
const forecast = (latitude, longitude, callback) => {
const url = 'https://api.darksky.net/forecast/0466bccb953c0b9daeb091a529da2c0d/' + latitude + ',' + longitude + '?units=si'
request({ url: url, json: true }, (error, response) => {
request({ url, json: true }, (error, {body}) => {
if (error) {
callback('Unable to connect to weather service!', undefined)
} else if (response.body.error) {
} else if (body.error) {
callback('Unable to find location', undefined)
} else {
callback(undefined, response.body.daily.data[0].summary + ' It is currently ' + response.body.currently.temperature + ' degrees out. There is a ' + response.body.currently.precipProbability + '% chance of rain.')
callback(undefined, body.daily.data[0].summary + ' It is currently ' + body.currently.temperature + ' degrees out. There is a ' + body.currently.precipProbability + '% chance of rain.')
}
})
}

View File

@@ -3,16 +3,16 @@ const request = require('request')
const geocode = (address, callback) => {
const url = 'https://api.mapbox.com/geocoding/v5/mapbox.places/' + encodeURIComponent(address) + '.json?access_token=pk.eyJ1IjoiamF5d2xsIiwiYSI6ImYyZjkyMGNlOTgyNGQ5ZWM5ZDExN2FjNGYwMDZmNTQ4In0.y3lv5ddmGhVNSL7wfMpB0g&limit=1'
request({ url: url, json: true }, (error, response) => {
request({ url, json: true }, (error, {body}) => {
if (error) {
callback('Unable to connect to location services!', undefined)
} else if (response.body.features.length === 0) {
} else if (body.features.length === 0) {
callback('Unable to find location. Try another search.', undefined)
} else {
callback(undefined, {
latitude: response.body.features[0].center[1],
longitude: response.body.features[0].center[0],
location: response.body.features[0].place_name
latitude: body.features[0].center[1],
longitude: body.features[0].center[0],
location: body.features[0].place_name
})
}
})