Skip to content
Snippets Groups Projects
Commit 22a6f910 authored by Joni Laukka's avatar Joni Laukka
Browse files

Device location update interval added. Location will be updated every second.

parent 31817ed3
No related branches found
No related tags found
1 merge request!3Get own location
This commit is part of merge request !3. Comments created here will be created in the context of that merge request.
...@@ -8,14 +8,35 @@ class UserMap extends Component { ...@@ -8,14 +8,35 @@ class UserMap extends Component {
ownLat: null, ownLat: null,
ownLng: null, ownLng: null,
} }
this.DeviceLocationUpdater = null;
this.updateDeviceLocation = this.updateDeviceLocation.bind(this);
} }
componentDidMount(){ componentDidMount(){
this.startDeviceLocationUpdater();
}
componentWillUnmount(){
if(this.DeviceLocationUpdater != null){
clearInterval(this.DeviceLocationUpdater);
}
}
startDeviceLocationUpdater(){
this.DeviceLocationUpdater = setInterval(this.updateDeviceLocation, 1000);
}
updateDeviceLocation(){
this.getCurrentPosition((position) => { this.getCurrentPosition((position) => {
this.setState({ this.setCurrentPosition(position);
ownLat: position.coords.latitude, });
ownLng: position.coords.longitude, }
});
setCurrentPosition(position){
this.setState({
ownLat: position.coords.latitude,
ownLng: position.coords.longitude,
}); });
} }
......
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