我想更改 PositionChanged 事件处理程序中的 DesiredAccuracy 和 ReportInterval,以便我可以动态更改不同位置的位置更新频率。
我做了这样的事情,
void geolocator_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
{
geolocator.StatusChanged -= geolocator_StatusChanged;
geolocator.PositionChanged -= geolocator_PositionChanged;
geolocator.DesiredAccuracy = PositionAccuracy.High;
geolocator.ReportInterval = 5 * 1000;
geolocator.StatusChanged += geolocator_StatusChanged;
geolocator.PositionChanged += geolocator_PositionChanged;
}
但问题是我得到了
$exception {System.Exception: Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT))
在
Windows.Devices.Geolocation.Geolocator.put_DesiredAccuracy(PositionAccuracy value)
我不明白这个异常,因为它没有说明原因。
我怎样才能做到这一点(动态更改准确性和报告间隔)?
谢谢。
最佳答案
根据 this Microsoft article ,您的异常表明您已从手机设置中禁用定位服务:
catch (Exception ex)
{
if ((uint)ex.HResult == 0x80004004)
{
// the application does not have the right capability or the location master switch is off
StatusTextBlock.Text = "location is disabled in phone settings.";
}
//else
{
// something else happened acquring the location
}
}
关于windows - 是否可以在 PositionChanged 事件处理程序中更改 Geolocator 的 DesiredAccuracy 和 ReportInterval?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13720945/