Please provide the following:
- SDK Version: 39
- Platforms(Android/iOS/web/all): Android && IOS
I am using the Location API from Expo for a compass, the app uses the Location.watchHeadingAsync and the watchPositionAsync for orientation. The problem that I am facing is the removal of the listeners, the watchPositionAsync gets deleted successfully, but not the watchHeadingAsync listener. The error that I get is: ‘this.HeadingListener.remove is not a function’. This is the code that I am using:
componentDidMount() {
if(this.getPermission()) {
this._subscribe();
this._getLocation();
}
}
getPermission = async() => {
let { status } = await Location.requestPermissionsAsync();
if (status !== 'granted') {
return false;
} else {
return true;
}
}
componentWillUnmount() {
this.HeadingListener.remove()
this.LocationListener.remove()
}
_subscribe = async() => {
this.HeadingListener = Location.watchHeadingAsync((response) => {
//console.log(response)
this.setState({Heading: response.magHeading, Accuracy: response.accuracy })
})
}
_getLocation = async() => {
this.LocationListener = await Location.watchPositionAsync({accuracy: 6, timeInterval: 2000, distanceInterval: 0}, (response) => {
console.log('Homescreen location')
this.setState({lat: response.coords.latitude})
this.setState({long: response.coords.longitude})
})
}