Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在api中将英制单位转换为公制单位?_Javascript_Openweathermap - Fatal编程技术网

Javascript 如何在api中将英制单位转换为公制单位?

Javascript 如何在api中将英制单位转换为公制单位?,javascript,openweathermap,Javascript,Openweathermap,如何将此API结果从英制单位转换为公制单位。下面是FetchAPI的代码 button.addEventListener('click', function() { fetch('http://api.openweathermap.org/data/2.5/weather?q=' + inputValue.value + '&APPID=501cd47da792c61ec790cdbc6913fced') .then(Response => Response.json(

如何将此API结果从英制单位转换为公制单位。下面是FetchAPI的代码

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))
})

正如@Orkhan Alikhanov在评论中所说的,您可以在这个API的url上向metric添加unit参数。像这样:

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))
})

追加
&单位=公制