Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

New Weather API in SDK 4.3

Hello,

I'm having some trouble implementing the new Weather API in SDK Version 4.3

It doesn't seem to use my current location, instead it uses the sample location from the documentation.

The documentation doesn't state that I have to pass the location myself.

 

Here is the code I used:

import weather from "weather";
weather
      .getWeatherData({temperatureUnit: "celsius"})
      .then(data => {
        console.log(JSON.stringify(data));
        if (data.locations.length > 0) {
          let condition = data.locations[0].currentWeather.weatherCondition;
          condition = mapping_codes[Providers.fitbit][condition];

          const weather = {
            temperatureC: Math.floor(data.locations[0].currentWeather.temperature),
            temperatureF: Math.floor(data.locations[0].currentWeather.temperature) * 9 / 5 + 32,
            location: data.locations[0].name,
            coord: { "lon": longitude,"lat": latitude},
            description: '',
            isDay: true,
            conditionCode : condition !== undefined ? condition : Conditions.Unknown,
            realConditionCode: data.locations[0].currentWeather.weatherCondition,
            sunrise:  1000,
            sunset:  1000
          };

          resolve(weather);
        }else{
          reject('');
        }

And I'm getting the following response:

{
    "temperatureUnit": "celsius",
    "locations": [
        {
            "id": "",
            "name": "Yosemite",
            "timeOffsetUTC": -25200,
            "currentWeather": {
                "epochTime": 1627314027,
                "weatherCondition": 32,
                "temperature": 22
            },
            "days": [
                {
                    "epochTimeMidnight": 1627257600,
                    "day": 1,
                    "weatherCondition": 1,
                    "precipitationProbability": 5,
                    "epochSunriseTime": 1627282800,
                    "epochSunsetTime": 1627326000,
                    "highTemperature": 24,
                    "lowTemperature": 17,
                    "hours": [
                        {
                            "epochTimeStart": 1627311600,
                            "hour": 17,
                            "temperature": 24,
                            "weatherCondition": 7
                        },
                        {
                            "epochTimeStart": 1627315200,
                            "hour": 18,
                            "temperature": 22,
                            "weatherCondition": 18
                        },
                        {
                            "epochTimeStart": 1627318800,
                            "hour": 19,
                            "temperature": 21,
                            "weatherCondition": 7
                        }
                    ]
                }
            ]
        }
    ]
}

Everything togetherEverything together

Best Answer
4 REPLIES 4

Servus, dieser Sab ist nun gekapert, tschau und meddl off.

Best Answer
0 Votes

Thanks for raising this. There's seems to be an anomaly between Android and iOS and we're investigating.

Best Answer
0 Votes

Noticing this same issue with the latest 6.0 sdk, was this ever resolved?  Seems like the location doesn't change from Yosemite.

Best Answer
0 Votes

Yes, the weather API works for me now. When I use the simulator it is still always sample data from Yosemite but it will use the correct location on a real device.

Best Answer