I am building a google map component and I'm trying to set the lng and lat of the user into the state.
position.coords.latitude
and position.coords.longitude
logs the right coordinates but when I try to set them into state I get the error in the title.
constructor(props) {
super(props);
this.state = {
userLatitude: 0,
userLongitude: 0
}
}
componentDidMount() {
navigator.geolocation.getCurrentPosition(function(position) {
console.log(position.coords.latitude + " " + position.coords.longitude);
this.setState({userLatitude: position.coords.latitude});
this.setState({userLongitude: position.coords.longitude});
});
}