Hi I'm new to React so bear with me. I'm want to store geoposition as a state. Seems nifty since any change in position will trigger a render, which is exactly what I want. During development I have a button that manual triggers the event by accessing the lastPosition
. But when I do. The state is "undefined". Any clue why?
export default class FetchProject extends Component {
constructor(props) {
super(props);
this.state = {
initialPosition: 'unknown',
lastPosition: 'unknown',
};
}
//code that sets lastposition
componentDidMount() {
....
}
_onPressGET (){
console.log("PressGET -> " + this.state); //undefined
var northing=this.state.initialPosition.coords.latitude;
//triggers error
}
render() {
return (
<View style={styles.container}>
<TouchableHighlight onPress = {this._onPressGET} style = {styles.button}>
<Text>Fetch mailbox</Text>
</TouchableHighlight>
</View>
);
}
}