finish 4
This commit is contained in:
parent
20d4f30994
commit
f9b6dba4d2
12533
react/4/seasons/package-lock.json
generated
Normal file
12533
react/4/seasons/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
|
@ -6,18 +6,29 @@ class App extends React.Component {
|
||||||
// specific to JS not to React
|
// specific to JS not to React
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
this.state = { lat: null }
|
this.state = { lat: null, errorMessage: '' }
|
||||||
|
|
||||||
window.navigator.geolocation.getCurrentPosition(
|
window.navigator.geolocation.getCurrentPosition(
|
||||||
postion => {
|
postion => {
|
||||||
this.setState({ lat: postion.coords.latitude })
|
this.setState({ lat: postion.coords.latitude })
|
||||||
},
|
},
|
||||||
err => console.log(err)
|
err => {
|
||||||
|
this.setState({ errorMessage: err.message })
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return <div>Latitude: {this.state.lat}</div>
|
|
||||||
|
if (this.state.errorMessage && !this.state.lat) {
|
||||||
|
return <div>Error: {this.state.errorMessage}</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.state.errorMessage && this.state.lat) {
|
||||||
|
return <div>Latiture: {this.state.lat}</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
return <div>Loading...</div>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
|
|
Loading…
Reference in a new issue