Windows Phone 8 Geolocator can't set desiredAccuracy = High AND tie into PositionChanged event

…衆ロ難τιáo~ 提交于 2019-12-08 03:10:00

问题


background: I'm well versed in WPF/XAML, but new to Windows Phone 8.

Hopefully there is just something stupid that I'm missing...

I want DesiredAccuracy to be high, but I also want to hook into the PositionChanged event.

When the below code reaches _GeoLocator.DesiredAccuracy = PositionAccuracy.High; it throws an abort. If it off, everything works but I really want high accuracy.

It seems the two are mutually exclusive of one another.

Error message is: Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT)). I have Location capabilities enabled.

Example of offending code:

    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:


You have to set "DesiredAccuracy" before "PositionChanged" event handler (Similar question).

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


来源:https://stackoverflow.com/questions/19172451/windows-phone-8-geolocator-cant-set-desiredaccuracy-high-and-tie-into-positio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!