簡體   English   中英

如何在 api 中將英制單位轉換為公制單位?

[英]How to convert imperial to metric units in api?

如何將此 API 結果從英制單位轉換為公制單位。 下面是獲取 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))
})

就像@Orkhan Alikhanov 在評論中所說的那樣,您可以在 API 的 url 上將 unit 參數添加到 metric。 像這樣:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM