-1

I am developing a map where I track user's location via navigator.geolocation.watchPosition towards it's destination. Now what i want is to track location of the user in real-time when he has logged in to the web portal for this i am using watch position which help me update the latest location of user momentarily. The Issue is am facing is when the user changes the tab, or moves the tab in the background, or when the browser becomes inactive watchPosition stops fetching the location due to which i am unable to update location on real-time basis. For this I tried using navigator.geolocation.getCurrentPosition as well but what i experienced is that although the getCurrentPosition api was being triggered it wasn't returning the location but as soon as i moved back to the tab i started receiving the positions.

I had looked into some possible solutions via service-worker but due to it's limitation we won't be able to fetch location through it.

It would be great if someone could suggest a possible solution for my problem?

2
  • Please see this answer for complete details Commented Aug 1, 2024 at 3:06
  • It is possible for browser vendors and W3C to spec and implement this safely! See previous discussion for complete details. Commented Aug 15, 2024 at 1:38

1 Answer 1

0

For your use case, it seems JavaScript, or at least the way you'd like to implement it, is not the best technology for your project. There is no way for a web page to retrieve a users location whilst in the background, if there were, this would introduce a plethora of privacy issues where a user may be tracked unknowingly by a webpage in the background. Instead, look at using a native application to retrieve the location data, this could be registered as a service on your users devices so that it may be run in the background.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.