1
0
This commit is contained in:
Jason Williams 2019-08-25 15:16:02 -06:00
parent bc68915cbc
commit 1d6ada3e91
2 changed files with 23 additions and 29 deletions

View File

@ -1,35 +1,12 @@
const request = require('request')
const geocode = require('./utils/geocode') const geocode = require('./utils/geocode')
const forecast = require('./utils/forecast')
const url = 'https://api.darksky.net/forecast/0466bccb953c0b9daeb091a529da2c0d/37.8267,-122.4233?units=si'
// request({ url: url, json: true }, (error, response) => {
// if (error) {
// console.log('Unable to connect to weather service!')
// } else if (response.body.error) {
// console.log('Unable to find location')
// } else {
// console.log(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.')
// }
// })
// const geocodeURL = 'https://api.mapbox.com/geocoding/v5/mapbox.places/philadelphia.json?access_token=pk.eyJ1IjoiamF5d2xsIiwiYSI6ImYyZjkyMGNlOTgyNGQ5ZWM5ZDExN2FjNGYwMDZmNTQ4In0.y3lv5ddmGhVNSL7wfMpB0g&limit=1'
// request({ url: geocodeURL, json: true }, (error, response) => {
// if (error) {
// console.log('Unable to connect to location services!')
// } else if (response.body.features.length === 0) {
// console.log ('Unable to find location. Try another search.')
// } else {
// const latitude = response.body.features[0].center[1]
// const longitude = response.body.features[0].center[0]
// console.log(latitude, longitude)
// }
// })
geocode('Boston', (error, data) => { geocode('Boston', (error, data) => {
console.log('Error', error) console.log('Error', error)
console.log('Data', data) console.log('Data', data)
}) })
forecast(-75.7088, 44.1545, (error, data) => {
console.log('Error', error)
console.log('Data', data)
})

View File

@ -0,0 +1,17 @@
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) => {
if (error) {
callback('Unable to connect to weather service!', undefined)
} else if (response.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.')
}
})
}
module.exports = forecast