Search code examples
windows-phone-7locationbackground-processbackground-agents

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


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.


Solution

  • 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.