Agontuk / react-native-geolocation-service

React native geolocation service for iOS and android
https://www.npmjs.com/package/react-native-geolocation-service
MIT License
1.61k stars 291 forks source link

WatchPosition is not working #282

Closed justkapoor closed 3 years ago

justkapoor commented 3 years ago

My implementation is like: I get the current position & subscribe to watch so as to get the updated position. Below are the programs used for Getting one time location & subscribing to wachposition. Please help me in the fixing the issue.

const getOneTimeLocation = () => {
    Geolocation.getCurrentPosition(
      //Will give you the current location
      (position) => {
        console.log(position, 35);
        setCurrentLat(position.coords.latitude);
        setCurrentLng(position.coords.longitude);
      },
      (error) => {
        console.warn(error, 38);
    },
      {
        enableHighAccuracy: true,
        timeout: 15000,
        maximumAge: 0,
        forceRequestLocation: true,
        showLocationDialog: true,
        accuracy: 5
      },
    );
  };

const subscribeLocationLocation = () => {
    watchID = Geolocation.watchPosition(
      (position) => {
        console.log(position, 51);
        setCurrentLat(position.coords.latitude);
        setCurrentLng(position.coords.longitude);
      },
      (error) => {
          console.warn(error, 54);
      },
      {
        enableHighAccuracy: true,
        timeout: 15000,
        maximumAge: 0,
        forceRequestLocation: true,
        showLocationDialog: true,
        accuracy: 5
      },
    );
    setWatchId(watchID);
};
iamrraj commented 3 years ago

Hi @justkapoor How did you solve this issue can you please send me code ?