Windows Phone 8 - Geolocator PositionChanged监听器在一段时间后死亡

Jos*_*eal 6 c# mobile geolocation windows-phone-8

我正在使用Geolocator对象设置PositionChanged侦听器

var geolocator = new Geolocator();
geolocator.PositionChanged += Geolocator_PositionChanged;
Run Code Online (Sandbox Code Playgroud)

它工作正常一段时间.但经过一段时间没有用户互动(+ - 4小时)它停止接收位置变化,我认为因为WP8只是杀死它.这可能是从ms开始的,但这对我的app模型来说太可怕了.

我所做的是另外设置PeriodicTask并发送位置.这样运行没有任何问题,但如果用户改变他的位置,我无法真正跟踪它.

问题是:无论如何在没有用户交互的情况下唤醒这个Geolocator?它可以通过PeriodicTask甚至是PositionChanged.

我已经尝试在PositionChanged委托中已经实例化了一个新的Geolocator,但这不起作用.

很感谢任何形式的帮助.谢谢!

Ofi*_*fir 2

这似乎是某种 GC 杀死/禁用实例的原因。

尝试使用geolocator.addEventListener("statuschanged", onStatusChanged);

Windows.Devices.Geolocation.PositionStatus.disabled并在状态为或时重新启动对象Windows.Devices.Geolocation.PositionStatus.notAvailable

请参阅Geolocator.StatusChanged | statuschanged 事件了解更多详细信息。

希望我有帮助