In part one ππ (Part One) we made our API get the longitudes of the location we want. In this part we are really going to get the weather data of the location using another API.
We are going to use Weather Stack.The first step to using the API is to authenticate with your weatherstack account's unique API access key, which can be found in your account dashboard after registration. To authenticate with the API, simply use the base URL below and pass your API access key to the API's access_key
parameter.
http://api.weatherstack.com/current
? access_key = YOUR_ACCESS_KEY
& query = {coordinates}
Weather Stack is easy to integrate and there is an option of passing the place name you want to get the weather here is an example
http://api.weatherstack.com/current
? access_key = YOUR_ACCESS_KEY
& query = New York
But today we are going to use the geoCoding where we will pass the coordinates returned from the geoCode function we created in part One.In part one the function returns an object so to access the latitude will be cordinates.latitude
and longitude we use cordinates.latitude
.
geoCode("Nairobi").then(async function(cordinates){
response = await axios.get(`http://api.weatherstack.com/current?access_key=**your Accesskey&query=${cordinates.latitude},${cordinates.longitude}&units=m`)
const description=response.data.current.weather_descriptions[0];
const temperature = response.data.current.temperature;
const timeTaken = response.data.current.observation_time;
})
This code will get us the weather data but we are going to only use the description ,temperature and time the data was recorded
.
In the next part we will be structuring our files and start working with express
Top comments (0)