Windows Phone 8 Geolocator无法设置desiredAccuracy = High并绑定到PositionChanged事件

时间:2013-10-04 02:58:05

标签: c# .net windows-phone-8 geolocation abort

背景:我非常精通WPF / XAML,但不熟悉Windows Phone 8。

希望我错过了一些愚蠢的东西......

我希望DesiredAccuracy很高,但我也希望挂钩到PositionChanged事件。

当下面的代码到达_GeoLocator.DesiredAccuracy = PositionAccuracy.High;它引发了堕胎。如果它关闭,一切正常,但我真的想要高精度。

似乎两者互相排斥。

错误消息是:操作已中止(HRESULT异常:0x80004004(E_ABORT))。我启用了位置功能。<​​/ p>

违规代码示例:

    public MainPage()
    {
        InitializeComponent();

        _GeoLocator.MovementThreshold = 1;

        _GeoLocator.PositionChanged += (Geolocator sender, PositionChangedEventArgs args) =>
        {
            //UpdateLocation(args);
            Console.WriteLine("Position Changed");
        };

        //THIS WILL THROW...WHY??   IF I COMMENT OFF POSITIONCHANGED ABOVE, IT WORKS FINE.
        _GeoLocator.DesiredAccuracy = PositionAccuracy.High;
    }

1 个答案:

答案 0 :(得分:4)

你必须设置&#34; DesiredAccuracy&#34;之前&#34; PositionChanged&#34;事件处理程序(Similar question)。

_GeoLocator.MovementThreshold = 1;
_GeoLocator.DesiredAccuracy = PositionAccuracy.High;
_GeoLocator.PositionChanged += (Geolocator sender, PositionChangedEventArgs args) =>
    {
        //UpdateLocation(args);
        Console.WriteLine("Position Changed");
    };