Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Latitude and longitude does not get updated after geolocation change #21

Open
7hong13 opened this issue Oct 1, 2020 · 1 comment
Open

Comments

@7hong13
Copy link

7hong13 commented Oct 1, 2020

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]);
@behnammodi
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants