37 lines
892 B
JavaScript
37 lines
892 B
JavaScript
import React from 'react'
|
|
import ReactDOM from 'react-dom'
|
|
|
|
class App extends React.Component {
|
|
|
|
// specific to JS not to React
|
|
constructor(props) {
|
|
super(props)
|
|
this.state = { lat: null, errorMessage: '' }
|
|
|
|
window.navigator.geolocation.getCurrentPosition(
|
|
postion => {
|
|
this.setState({ lat: postion.coords.latitude })
|
|
},
|
|
err => {
|
|
this.setState({ errorMessage: err.message })
|
|
}
|
|
)
|
|
}
|
|
|
|
render() {
|
|
|
|
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(
|
|
<App />,
|
|
document.querySelector('#root')
|
|
) |