|
@@ -14,18 +14,62 @@ class App extends Component {
|
|
|
};
|
|
|
};
|
|
|
|
|
|
- change = () => {
|
|
|
+ change = (name) => {
|
|
|
const newPersons = [...this.state.persons];
|
|
|
- newPersons.map( person => {person.speed = person.speed + Math.floor((Math.random() * 10) + 1)})
|
|
|
+ newPersons.map( person => {
|
|
|
+ if (name == person.name) {
|
|
|
+ person.speed = person.speed + Math.floor((Math.random() * 10) + 1)
|
|
|
+ }
|
|
|
+
|
|
|
+ })
|
|
|
+ this.setState({ persons: newPersons });
|
|
|
+ }
|
|
|
+
|
|
|
+ getLocation = (name) => {
|
|
|
+ const newPersons = [...this.state.persons];
|
|
|
+
|
|
|
+ if (navigator.geolocation) { //check if geolocation is available
|
|
|
+ navigator.geolocation.getCurrentPosition(function(position){
|
|
|
+ console.log(position);
|
|
|
+ newPersons.map( person => {
|
|
|
+ if (name == person.name) {
|
|
|
+ person.longitude = position.coords.longitude
|
|
|
+ person.latitude = position.coords.latitude
|
|
|
+ }
|
|
|
+ })
|
|
|
+ });
|
|
|
+ }
|
|
|
this.setState({ persons: newPersons });
|
|
|
}
|
|
|
|
|
|
render (){
|
|
|
- setTimeout(this.change, 5000)
|
|
|
+ setTimeout(this.getLocation, 2000)
|
|
|
|
|
|
return (
|
|
|
<div id="wrapper">
|
|
|
<Tables persons={persons}/>
|
|
|
+ <div id="debug"> </div>
|
|
|
+ <button
|
|
|
+ onClick={ () => {
|
|
|
+ this.getLocation("Bernie");
|
|
|
+ }}
|
|
|
+ > Bernie </button>
|
|
|
+ <button
|
|
|
+ onClick={ () => {
|
|
|
+ this.getLocation("Martin");
|
|
|
+ }}
|
|
|
+ > Martin </button>
|
|
|
+ <button
|
|
|
+ onClick={ () => {
|
|
|
+ this.getLocation("Simon");
|
|
|
+ }}
|
|
|
+ > Simon </button>
|
|
|
+ <button
|
|
|
+ onClick={ () => {
|
|
|
+ this.getLocation("Lukas");
|
|
|
+ }}
|
|
|
+ > Lukas </button>
|
|
|
+
|
|
|
</div>
|
|
|
);
|
|
|
}
|