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))
})
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))
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.