Revert to user location from map with better GPS accuracy
This commit is contained in:
@@ -15,36 +15,35 @@ export class Geolocation extends Component {
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
reactAutoBind(this)
|
||||
|
||||
if (props.watch) {
|
||||
this.intervalId = setInterval(this.updateLocation, config.geoSampleDelay)
|
||||
} else {
|
||||
this.intervalId = -1
|
||||
}
|
||||
this.watchId = -1
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.updateLocation()
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
if (this.intervalId !== -1) {
|
||||
clearInterval(this.intervalId)
|
||||
this.intervalId = -1
|
||||
}
|
||||
}
|
||||
|
||||
updateLocation() {
|
||||
navigator.geolocation.getCurrentPosition(
|
||||
(position) => {
|
||||
this.props.onUpdate(position)
|
||||
|
||||
if (this.props.watch) {
|
||||
;(this.watchId = navigator.geolocation.watchPosition((position) =>
|
||||
this.props.onUpdate(position)
|
||||
)),
|
||||
null,
|
||||
{ distanceFilter: 5, maximumAge: 0, enableHighAccuracy: true }
|
||||
}
|
||||
},
|
||||
null,
|
||||
{ distanceFilter: 5, maximumAge: 0, enableHighAccuracy: true }
|
||||
)
|
||||
}
|
||||
|
||||
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