watchPosition is not working for me on Either Android and iOS

See original GitHub issue

I want to get user’s location after every second in app so that I can use latest coordinates to change my Map marker and somethings more, but this is not working for me, I have done everything as doc said and also have all the permission given on my mobile app but nothing is working for me. I have made a separate hook for watching position here is the code: `const useWatchLocation = () => { const dispatch = useDispatch(); const [subscriptionId, setSubscriptionId] = useState<number | null>(null);

const watchPosition = () => {
    try {
        const watchID = Geolocation.watchPosition(
            (position) => {
                let location: CURRENT_LOCATION = formatLocation(position.coords.latitude, position.coords.longitude);
                console.log('location', location);
                dispatch(setUserLocation(location));
            },
            (error) => { _showConsoleError(`Error while watching location: ${error}`) },
            {
                enableHighAccuracy: true,
                fastestInterval: 1000,
            }
        );
        setSubscriptionId(watchID);
    } catch (error) {
        _showConsoleError(`Error while watching location: ${error}`);
    }
};

const clearWatch = () => {
    subscriptionId !== null && Geolocation.clearWatch(subscriptionId);
    setSubscriptionId(null);
};

useEffect(() => {
    return () => {
        clearWatch();
    };
}, []);

return {
    watchPosition,
    clearWatch,
}

}

export default useWatchLocation`

You can see that I’m updating redux state upon on new location. I have used this location state as dependency in another screen, here is the code:

useEffect(() => { if (location && mapRef && mapRef.current) { let camera: Camera = { center: { latitude: location.latitude, longitude: location.longitude }, zoom: 18, altitude: undefined, heading: 0, pitch: 0, }; mapRef.current.animateCamera(camera); } }, [location])

I’m also showing coordinates using Text so that I can see that on moving location is also updating in mobile application but nothing is working, can anyone please help me out in this?

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Haseeba393commented, Nov 21, 2022

I have followed the exact example code, given all permissions on both Android and iOS but nothing is working

0reactions
Haseeba393commented, Nov 21, 2022

I’m using this one as well, but not able to get updated location

Read more comments on GitHub >

github_iconTop Results From Across the Web

react native - navigator.geolocation.watchPosition not working ...
In the simulator my application works perfectly, but when I deploy it to my iphone the returning position (by getCurrentPosition and ...
Read more >
iOS watchPosition problem · Issue #151 - GitHub
When subscribing to the watchPosition the event function is first called 2-3 times. Then during the application stay in the foreground the event ......
Read more >
watchPosition constantly firing - Google Groups
I built a test app for watchPosition. For the test I laid the phone next to me and expected that it would not...
Read more >
Geolocation disabled when Chrome is in the background or ...
geolocation.watchPosition is followed -- as the device moves the position updates should be fed back into the script. What went wrong?
Read more >
Ios geolocation keep getting time out - Ionic Forum
hi, am trying to use the ngcordova geolocation plugin ( watchPosition ) in my ionic ios app. but am keep getting Time Our...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found