xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

Metric temperature and Imperial temperature All In One

Metric temperature and Imperial temperature All In One

Metric and Imperial / 公制和英制

Metric temperature

公制温度

Imperial temperature

英制温度

Celsius / Fahrenheit

摄氏度 / 华氏度

demo

Weather API


/**
 * Get's the latest forecast data from the network.
 *
 * @param {string} coords Location object to.
 * @return {Object} The weather forecast, if the request fails, return null.
 */
function getForecastFromNetwork(coords) {
  console.log('coords =', coords);
  // console.log('coords =', coords);
  // const location = req.params.location || '40.7720232,-73.9732319';
  const location = '40.7720232,-73.9732319';
  const API_KEY = `31977d6102fca95a51a571a081d05538`;
  const BASE_URL = `https://api.openweathermap.org/data/2.5/onecall`;
  // const url = `${BASE_URL}/${API_KEY}/${location}`;
  const url = `${BASE_URL}?lat=${latitude}&lon=${longitude}&appid=${API_KEY}&units=imperial`;
  // const url = `https://pwa.xgqfrms.xyz/pwa-app/weather-api.json`;
  // const url = `https://api.darksky.net/forecast/1dda89e666ce89b777d2412eac3026d8/${coords}`;
  // const url = `/forecast/${coords}`;
  return fetch(url)
    .then((response) => {
      return response.json();
    })
    .then(json => {
      console.log(`network json`, json);
    })
    .catch((err) => {
      console.error('Error getting data from cache', err);
      return null;
    });
}

units=imperial

https://api.openweathermap.org/data/2.5/onecall?lat=31.2243085&lon=120.9162955&appid=202277d6102fca95a51a571a081d0666&units=imperial

refs

https://en.wikivoyage.org/wiki/Metric_and_Imperial_equivalents



©xgqfrms 2012-2020

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2022-04-26 14:15  xgqfrms  阅读(163)  评论(1编辑  收藏  举报