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 { ...@@ -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);
......
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