Reputation: 11
How do i convert this API results from imperial to metric units. Below is the code for fetch api.
button.addEventListener('click', function() {
fetch('http://api.openweathermap.org/data/2.5/weather?q=' + inputValue.value + '&APPID=501cd47da792c61ec790cdbc6913fced')
.then(Response => Response.json())
.then(data => console.log(data))
})
Upvotes: 1
Views: 859
Reputation: 48
Like @Orkhan Alikhanov said in the comment, you can add the unit argument to metric on the url for this API. Like this :
button.addEventListener('click', function() {
fetch('http://api.openweathermap.org/data/2.5/weather?q=' + inputValue.value + '&units=metric&APPID=501cd47da792c61ec790cdbc6913fced')
.then(Response => Response.json())
.then(data => console.log(data))
})
Upvotes: 1