use-position icon indicating copy to clipboard operation
use-position copied to clipboard

Latitude and longitude does not get updated after geolocation change

Open 7hong13 opened this issue 5 years ago • 1 comments

Hi, I want to update latitude and longitude as browser detects geolocation change. So I just followed what document says, but it doesn't seem to work. It always returns the same latitude and longitude about where I called usePosition() for the very first time. I can't figure out what the problem is. Below is my code:

  const watch = true;
  const [currPosition, setCurrPosition] = useState({
    lat: 0,
    long: 0,
  })
  const { latitude, longitude, timestamp, accuracy, error } = usePosition(
    watch,
    { enableHighAccuracy: true }
  );
 useEffect(() => {
    setCurrPosition({lat: latitude, long: longitude})
  }, [latitude, longitude]);

7hong13 avatar Oct 01 '20 07:10 7hong13

It works, could you add a codesandbox link for that?

behnammodi avatar Sep 29 '21 14:09 behnammodi