I use OpenWeatherMap API 5 days 3/ hour plan and I need to get just the hourly weather I use this endpoint
const req = `http://api.openweathermap.org/data/2.5/forecast?lat=${latitude}&lon=${longitude}&cnt=9&units=metric&appid=${
this.ApiKeyRef
}`;
when I read the Doc of API the parameter cnt=8 that Cover the all hourly of the day in the 12:00 Am to 12:00 pm, but the issue if I open the App in the night lets say 9:00 pm they will Get the next hourly Day To complete the cnt=8!
anyone have an idea to get just the hours in currently Day, if can you help me with this issue?
my Code :
fetchCallback = async () => {
const { latitude, longitude } = this.state;
const req = `http://api.openweathermap.org/data/2.5/forecast?lat=${latitude}&lon=${longitude}&cnt=9&units=metric&appid=${
this.ApiKeyRef
}`;
const callback = responseJson => {
// console.log(responseJson);
// console.log(responseJson.city.name);
};
await fetch(req)
.then(response => response.json())
.then(responseJson =>
this.setState({ isLoading: false, dataSource: responseJson }, () =>
callback(responseJson)
)
)
.catch(error => console.log(error));
};
render(){
return (
<View style={styles.details}>
<Text>Hourly</Text>
<FlatList
data={this.state.dataSource.list}
showsVerticalScrollIndicator={false}
horizontal={true}
renderItem={({ item }) => (
<View style={[styles.statusWeather]}>
<Image
resizeMode="center"
style={[
styles.ImgWeek,
{
width: 110,
height: 110,
alignSelf: "center"
}
]}
source={require("./assets/cloudySun.png")}
/>
<View style={{ alignItems: "center" }}>
<Text
style={[
styles.TextStatus,
{ fontSize: 19, padding: 0, color: "#263461" }
]}
>
<Moment element={Text} format="dddd hh:mm A">
{item.dt_txt}
</Moment>
</Text>
<Text style={[styles.TextStatus, { padding: 0 }]}>
A {item.weather[0].main}
</Text>
<Text style={styles.TextStatus}>
<Text style={{ color: "#263461" }}>
{item.main.temp_max}°
</Text>
<Text> | {item.main.temp_min} °</Text>
</Text>
</View>
</View>
)}
keyExtractor={(item, index) => index.toString()}
/>
</View>
);
}