Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there way to track user current location within service workers in PWA while app is in sleep mode?

Whether you're into jogging, or cycling and want to track your trips, or you manage a fleet of trucks, farm or mining vehicles or delivery bikes you need to track your geographical position while your Web App is backgrounded or your device is asleep.

I'm wondering if today's web applications PWA can support something like live tracking of user position in the background using service workers and send notifications.

Will this work in the service workers:

window.navigator.geolocation.getCurrentPosition(function(pos) {
  console.log('pos: ', pos);
});

while app is in the background?

like image 274
TariqN Avatar asked Mar 21 '19 23:03

TariqN


1 Answers

Short answer: No

Long answer: -

You are not alone in this problem. A million other developers have asked for this same functionality.

Please see the proposed TravelManager solution that W3C flatly refused to specify. UA vendors also refuse to implement for reasons known only to themselves. It's worse than that; W3C is trying to reinvent Geolocation as a Sensor and deferring any useful or novel functionality and wasting hundreds of thousands of dollars but more importantly, precious time.

For complete background please see (1)this or (2)this.

And for a good laugh/cry see (3)this.

(1) This is a thread from W3C ServiceWorker GitHub repository that first raised the issue/requirement for background geolocation on Sep 5, 2015. What is contained here is heaps of use cases, irrefutable evidence of high user/developer demand, and proposed solutions. I was censored from all W3C github repositories because of my posts in this thread yet I leave you to judge the content from other authors in the unredacted thread version that can be found here.

(2) More users asking for the same background geolocation functionality at the W3C Geolocation repository.

(3) Evidence of the sheer madness currently underway at W3C to recast geolocation as a sensor while freely acknowledging that the existing API will continue to be supported and used and any novel functionality (especially a Background capability) will be deferred to a mythical version 2 with no timeline other than "Sometime after version 1". And they know the main-thread or web worker API they produce will not work in a ServiceWorker environment. Disbeleif!

(*) Please also be aware of the failed W3C Geofencing attempt. More money an precious time wasted. Note also, that they'll try to fob you off with the battery killing WakeLock() (As if you want your screen on when your jogging or you don't want to use any other Apps at all while geofence triggers are in place). Also just look how popular PhoneGap/Cordova is. Why? Background Geolocation!

(**) Yes this may come across as a bit of a rant but it's pretty hard to stayed emotionally detached after 4 years of watching personalities and egos prevent essential web app functionality that would allow us to go head to head with Native Apps :-(

No one has been able to find fault with the detailed TravelManager solution! (Yes we have to work on permissions but look at the debacle with the requestPermission() solution to the iOS/Safari shutdown of gyroscope et al sensors and we can agree that permissions are a work in progress for all. (When I say "debacle" that's because W3C have been ranting for years that requestPermission() is an "antipattern"))) See the W3C permissions repository for some more suggestions that were ignored.

like image 166
McMurphy Avatar answered Nov 14 '22 12:11

McMurphy