How can you update location data in Windows Phone in the background?

我只是一个虾纸丫 提交于 2020-01-05 10:25:24

问题


I just read that while Windows Phone 7.5 background tasks can poll for a location, they don't actually poll real-time from the GPS but rather the location API calls return a system-cached position that's only updated once every fifteen minutes.

That limitation of course completely invalidates any attempt at having navigation run in the background as you can get pretty damn far off-track in fifteen minutes, let alone that a background task can only run once every thirty minutes or so!

That said, Nokia's navigation app and reportedly Runtastic's app do continue tracking when in the background (i.e. not just under the lock screen) and both are in the marketplace meaning they have been approved, so does anyone know how they managed to do what the SDK supposedly doesn't support?

For reference, we don't actually need real-time tracking... maybe once a minuted or so, and we don't need that much accuracy... maybe 100 feet or so... but we do need more than we have been given. We just don't know how they're doing it in approved apps.


回答1:


You'll only be able to retrieve the location when your PeriodicTask executes (Approximately every ~30 minutes, depending on OS scheduling). The location data it fetches from GeoCoordinateWatcher will be from the OS's cache rather than directly from the GPS hardware. If nothing is running the OS will update this with coarse-grained data approximately every 15 minutes. However if an application has executed and retrieved fine-grained GPS hardware data than this will be the data you'll retrieve in your PeriodicTask. You can see examples of this by accessing the GPS in your foreground app and force-scheduling your PeriodicTask with ScheduledActionService.LaunchForTest.




回答2:


Based on my experience with background tasks, you will not be able to achieve what you want with either Periodic or ResourceIntensive background tasks.

Despite documentation claiming that they run every 30 minutes, my experience is that they run sporadically and unpredictably. Over the last 14 hours, my app's periodic task has run a total of 6 times, and this is pretty consistent every day - it runs about once every two hours. For resource intensive tasks, I find they usually run about twice a night. I guess the OS has to balance all the processes on the phone and all the other apps clamoring to run their background tasks, so sometimes yours doesn't make the cut. Obviously, your mileage may vary based on your phone (lumia 800 in my case) and the apps you have installed.

If you want to write an app that tracks your location once a minute, my advice would be to enable it to run under the lock screen by disabling idle detection and make sure it has a low memory footprint to conserve battery life.



来源:https://stackoverflow.com/questions/10238774/how-can-you-update-location-data-in-windows-phone-in-the-background

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!