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 together
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
Thanks for raising this. There's seems to be an anomaly between Android and iOS and we're investigating.
Best AnswerNoticing this same issue with the latest 6.0 sdk, was this ever resolved? Seems like the location doesn't change from Yosemite.
Best Answer