Skip to content
Snippets Groups Projects

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

Merged H9031 requested to merge location-permission-bugfix into development
1 file
+ 9
17
Compare changes
  • Side-by-side
  • Inline
+ 9
17
@@ -8,7 +8,6 @@ import {
@@ -8,7 +8,6 @@ import {
} from 'react-leaflet'
} from 'react-leaflet'
import DrawTools from './DrawTools.js'
import DrawTools from './DrawTools.js'
class UserMap extends Component {
class UserMap extends Component {
constructor(props){
constructor(props){
super(props);
super(props);
@@ -17,30 +16,21 @@ class UserMap extends Component {
@@ -17,30 +16,21 @@ class UserMap extends Component {
ownLng: null,
ownLng: null,
}
}
this.DeviceLocationUpdater = null;
this.watchPositionId = null;
this.updateDeviceLocation = this.updateDeviceLocation.bind(this);
}
}
componentDidMount(){
componentDidMount(){
this.startDeviceLocationUpdater();
this.getCurrentPosition((position) => {
 
this.setCurrentPosition(position);
 
});
}
}
componentWillUnmount(){
componentWillUnmount(){
if(this.DeviceLocationUpdater != null){
if(this.watchPositionId != null){
clearInterval(this.DeviceLocationUpdater);
navigator.geolocation.clearWatch(this.watchPositionId);
}
}
}
}
startDeviceLocationUpdater(){
this.DeviceLocationUpdater = setInterval(this.updateDeviceLocation, 1000);
}
updateDeviceLocation(){
this.getCurrentPosition((position) => {
this.setCurrentPosition(position);
});
}
setCurrentPosition(position){
setCurrentPosition(position){
this.setState({
this.setState({
ownLat: position.coords.latitude,
ownLat: position.coords.latitude,
@@ -60,7 +50,9 @@ class UserMap extends Component {
@@ -60,7 +50,9 @@ class UserMap extends Component {
maximumAge: 0
maximumAge: 0
}
}
navigator.geolocation.getCurrentPosition((position) =>{
if(this.watchPositionId != null){navigator.geolocation.clearWatch(this.watchPositionId);}
 
 
this.watchPositionId = navigator.geolocation.watchPosition((position) =>{
//success
//success
if(position != null){
if(position != null){
callback(position);
callback(position);
Loading