Geolocation Watch Handling Errors

When you’re using Geolocation watchPosition what is best practice for restarting the watch when someone navigates away from the application and then comes back, or turns off the location service and then turns it back on during the use of the application?

These both seem to trigger an error, but not sure if I should just be recursively call the watch after an error occurs or if there’s a better way. The application I’m working on requires the position of the user often for navigation. Everything is working as expected except for these two cases where an error is thrown and I’m not sure of best practice.

With the caveats that I have zero experience actually working with this, and real-world implementations don’t always match even normative specs, this looks to be the definitive word on how watchPosition is supposed to behave, and if I’m reading it correctly, you should be able to do whatever you want with the error, in terms of logging or reporting it, but you should be able to just ignore the error also if you wish.

The only error condition that terminates the process (and would therefore necessitate calling watchPosition again in order to receive any further updates) appears to be PERMISSION_DENIED. Any other error, watchPosition is mandated to soldier through until you call cancelWatch.

1 Like