Advertisement
Guest User

get location subscription in expo

a guest
Jul 16th, 2021
511
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. import * as Location from 'expo-location';
  2. let watchPositionRemove;
  3. removeLocationSubscription() {
  4. if (watchPositionRemove) {
  5. console.log("watchPositionRemove._W.remove() ");
  6. watchPositionRemove._W.remove();
  7. }
  8. }
  9. getLocationAsync = async () => {
  10. console.log("getLocationAsync() ", this._isMounted, watchPositionRemove);
  11. if (!this._isMounted) return;
  12. console.log("working");
  13. let { status } = await Location.requestForegroundPermissionsAsync();
  14. if (status !== 'granted') {
  15. console.log('Permission to access location was denied');
  16. }
  17. //write code for the app to handle GPS changes
  18. watchPositionRemove = Location.watchPositionAsync({
  19. accuracy: Location.Accuracy.BestForNavigation,
  20. timeInterval: 1000, distanceInterval: 1
  21. }, (location) => {
  22. console.log("OS sent Location ");
  23. const { latitude, longitude } = location.coords
  24. this.getStation0FromLocation(latitude, longitude)
  25. });
  26. };
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement