Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have looked into the forecast io (Darksky) api document, and find there are options that can change the temperature to celsius. I'm not sure how to use the code they provided.

Thanks for your help!

like image 483
Taieb Avatar asked Dec 14 '22 00:12

Taieb


2 Answers

You can add the si units options to your parameters in the request. This should give you back temperature in celsius. For example:

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();

I hope this helps.

like image 93
Brian Avatar answered Dec 28 '22 08:12

Brian


for dark sky API :

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

For Retrofit :

//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);

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

like image 23
Yogendra Avatar answered Dec 28 '22 09:12

Yogendra