最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin3浏览0评论

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?

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?

Share Improve this question edited Sep 5, 2024 at 13:31 VLAZ 29k9 gold badges62 silver badges83 bronze badges asked Mar 21, 2019 at 23:23 TariqNTariqN 7464 gold badges10 silver badges30 bronze badges 6
  • Please show what have you tried, Always ask a good question – T04435 Commented Mar 21, 2019 at 23:33
  • 2 I did not try anything, I'm making research to know if this is even possible to implement. I've read multiple conversation on this topic and I could not find that this is possible to implement in 2019. – TariqN Commented Mar 21, 2019 at 23:37
  • Nope. When the browser is in the background, it does not get location info. – Mathias Commented Mar 21, 2019 at 23:57
  • @TariqN did you find any solution for this? – Muhammad Usama Mashkoor Commented Jun 19, 2020 at 20:30
  • 1 @usama no I think it's impossible to implement this due to technical limitation of current web. – TariqN Commented Jul 3, 2020 at 10:19
 |  Show 1 more comment

1 Answer 1

Reset to default 17

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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论