This repository was archived by the owner on Aug 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
120 lines (111 loc) · 3.02 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import React, { Component } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import Weather from './Weather';
const API_KEY = "63d90416dea40c5f5f4231a9b0fe8654";
export default class App extends Component {
state = {
isLoaded: false,
temprature: null,
currentWeather: null,
error: null
};
_getWeather = (lat, long) => {
fetch(`https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${long}&APPID=${API_KEY}`)
.then(response => response.json())
.then(json => {
this.setState({
temprature: json.main.temp,
currentWeather: json.weather[0].main,
isLoaded: true
})
})
.catch(err => console.log(err))
}
_weatherLotation = () => {
setTimeout(lotate => this.setState({
currentWeather: "Clear",
temprature: 230,
isLoaded: true
}), 1000);
setTimeout(lotate => this.setState({
currentWeather: "Rain",
temprature: 230,
isLoaded: true
}), 2000);
setTimeout(lotate => this.setState({
currentWeather: "Thunderstorm",
temprature: 230,
isLoaded: true
}), 3000);
setTimeout(lotate => this.setState({
currentWeather: "Clouds",
temprature: 230,
isLoaded: true
}), 4000);
setTimeout(lotate => this.setState({
currentWeather: "Snow",
temprature: 230,
isLoaded: true
}), 5000);
setTimeout(lotate => this.setState({
currentWeather: "Drizzle",
temprature: 230,
isLoaded: true
}), 6000);
setTimeout(lotate => this.setState({
currentWeather: "Haze",
temprature: 230,
isLoaded: true
}), 7000);
setTimeout(lotate => this.setState({
currentWeather: "Mist",
temprature: 230,
isLoaded: true
}), 8000);
setTimeout(lotate => (
navigator.geolocation.getCurrentPosition(
position => {
this._getWeather(position.coords.latitude, position.coords.longitude);
}, error => this.setState({ error: error })
)
), 9000)
}
componentDidMount() {
this._weatherLotation()
}
render() {
const { temprature, currentWeather, isLoaded, error } = this.state;
return (
<View style={styles.container}>
{ isLoaded ? <Weather temp={ temprature } condition={ currentWeather } /> : (
<View style={styles.loading}>
<Text style={styles.loadingText}>Getting Weather</Text>
{ error ? <Text style={styles.errorText}>{ error }</Text> : null}
</View>
)}
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1
},
loading: {
flex: 1,
backgroundColor: "#FDF6AA",
justifyContent: "flex-end"
},
loadingText: {
paddingLeft: 25,
fontSize: 38,
marginBottom: 100,
fontWeight: "300"
},
errorText: {
paddingLeft: 25,
marginBottom: 40,
backgroundColor: "transparent",
color: "red"
}
});