如何使用 Darksky API 中的 "Options" 将温度从华氏度更改为摄氏度?

How to use the "Options" from the Darksky API to change the temperature from fahrenheit to celsius?

我查看了 forecast io (Darksky) api 文档,发现有选项可以将温度更改为摄氏度。我不确定如何使用他们提供的代码。

感谢您的帮助!

您可以将 si 单位选项添加到请求中的参数中。这应该以摄氏度为单位返回温度。例如:

const https = require('https');
var body = "";

const url = "https://api.darksky.net/forecast/your-key-goes-here/53.34929607,-6.26036167?units=si"

var req = https.request(url, (res) => {
      res.on('data', (d) => {
      body += d;
    });

    res.on('end', () => {
        var data = JSON.parse(body);
        console.log(data.currently.temperature);
    });
});

req.on('error', (e) => {
  console.error(e);
});

req.end();

希望对您有所帮助。

黑暗天空 API :

https://api.darksky.net/forecast/5dc71e8b06915dee1cac240d5805eb66/24.68,83.06?units=si&exclude=hourly,flags,offset

改造:

//https://api.darksky.net/forecast/5dc71e8b06915dee1cac240d5805eb66/24.68,83.06?units=si

@GET("/forecast/{apikey}/{latitude},{longitude}?")
Call <SkyWeatherAPI> getWeatherDarkSky(@Path("apikey") String apikey, @Path("latitude") String latitude,
                                       @Path("longitude") String longitude, @Query("units") String units);

调用 apiWeatherCall = mApiWeather.getWeatherDarkSky(API_KEY, "24.68","83.06", "si");