windows - 是否可以在 PositionChanged 事件处理程序中更改 Geolocator 的 DesiredAccuracy 和 ReportInterval?

标签 windows silverlight gps windows-phone windows-phone-8

我想更改 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/

相关文章:

c# - 在 Windows 平台上创建进入网站安全区域的应用程序

silverlight - 对象列表框和按钮

silverlight - 为什么要在 Silverlight 应用程序中使用 MVVM?

android - 在android中获取错误的Gps位置

ruby-on-rails - rails 回形针 - 错误处理缩略图

windows - 在路径上定位文件

c# - MVC .net 适合我的项目类型吗?

python - 如何根据距已知引用轨迹的距离过滤位置数据?

python - 根据.CSV格式的AVL(GPS)数据创建伪GTFS数据集

java - 使用 Java 的 AclFileAttributeView 获取通用文件夹权限(如 GENERIC_ALL)