Skip to content
Snippets Groups Projects
Commit db71aea9 authored by M3034's avatar M3034
Browse files

Merge branch 'location-permission-bugfix' into 'development'

GetCurrentPosition interval changed to WatchPosition so the device does not...

See merge request !5
parents 45a33b83 92e66ce9
No related branches found
No related tags found
1 merge request!5GetCurrentPosition interval changed to WatchPosition so the device does not...
......@@ -8,7 +8,6 @@ import {
} from 'react-leaflet'
import DrawTools from './DrawTools.js'
class UserMap extends Component {
constructor(props){
super(props);
......@@ -17,30 +16,21 @@ class UserMap extends Component {
ownLng: null,
}
this.DeviceLocationUpdater = null;
this.updateDeviceLocation = this.updateDeviceLocation.bind(this);
this.watchPositionId = null;
}
componentDidMount(){
this.startDeviceLocationUpdater();
this.getCurrentPosition((position) => {
this.setCurrentPosition(position);
});
}
componentWillUnmount(){
if(this.DeviceLocationUpdater != null){
clearInterval(this.DeviceLocationUpdater);
if(this.watchPositionId != null){
navigator.geolocation.clearWatch(this.watchPositionId);
}
}
startDeviceLocationUpdater(){
this.DeviceLocationUpdater = setInterval(this.updateDeviceLocation, 1000);
}
updateDeviceLocation(){
this.getCurrentPosition((position) => {
this.setCurrentPosition(position);
});
}
setCurrentPosition(position){
this.setState({
ownLat: position.coords.latitude,
......@@ -60,7 +50,9 @@ class UserMap extends Component {
maximumAge: 0
}
navigator.geolocation.getCurrentPosition((position) =>{
if(this.watchPositionId != null){navigator.geolocation.clearWatch(this.watchPositionId);}
this.watchPositionId = navigator.geolocation.watchPosition((position) =>{
//success
if(position != null){
callback(position);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment