I am trying to get the User's location in an Android React Native application. I've started by following the React Native Geolocation Tutorial but am not having any luck.
I have added the appropriate permissions to the Android project and inserted this code in the react native app:
componentDidMount() {
navigator.geolocation.getCurrentPosition(
(position) => {
var initialPosition = JSON.stringify(position);
this.setState({initialPosition});
},
(error) => alert(error.message),
{enableHighAccuracy: true, timeout: 20000, maximumAge: 1000}
);
console.log("Initial position: " + this.state.initialPosition)
}
I also have the initialPosition variable defined as 'unknown' just like in the tutorial. When the example runs, the initialPosition variable prints unknown. Then about 5 seconds later, the alert shows an 'undefined' error.
I am a bit confused as to what is going on because the error is null. Perhaps I am instantiating the "geolocation" incorrectly? Unfortunatly I am not able to find much information on this through searches so any help is appreciated.