Add in Geolocation component
This commit is contained in:
36
mobile/src/ui/Geolocation.js
Normal file
36
mobile/src/ui/Geolocation.js
Normal file
@@ -0,0 +1,36 @@
|
||||
import React, { Component } from "react"
|
||||
import { Image, View } from "react-native"
|
||||
import PropTypes from "prop-types"
|
||||
import autobind from "autobind-decorator"
|
||||
|
||||
export class Geolocation extends Component {
|
||||
static propTypes = {
|
||||
onUpdate: PropTypes.func.isRequired,
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
this.watchId = -1
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
navigator.geolocation.getCurrentPosition((position) => {
|
||||
this.props.onUpdate(position)
|
||||
this.watchId = navigator.geolocation.watchPosition((position) =>
|
||||
this.props.onUpdate(position)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
if (this.watchId !== -1) {
|
||||
navigator.geolocation.clearWatch(this.watchId)
|
||||
navigator.geolocation.stopObserving()
|
||||
this.watchId = -1
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
return null
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user