使用xaml在Windows 8商店应用中未触发PositionChanged事件

时间:2012-11-25 09:11:38

标签: xaml windows-runtime winrt-xaml winrt-async

在下面的代码中,事件PositionChanged永远不会被触发。我正在尝试在笔记本电脑中执行此代码。在执行任何代码之前,有没有办法检查设备中是否有GPS。

private async void Track_Click_1(object sender, RoutedEventArgs e)

    {
        locator = new Geolocator();
        locator.DesiredAccuracy = PositionAccuracy.High;
        locator.MovementThreshold = 10;
        locator.ReportInterval = 2000;
        locator.PositionChanged += locator_PositionChanged;
        locator.PositionChanged +=  new TypedEventHandler<Geolocator, PositionChangedEventArgs>(OnPositionChanged);


    }

    void locator_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
    {
        throw new NotImplementedException();
    }

    void OnPositionChanged(Geolocator sender, PositionChangedEventArgs args)
    {

        dAltitude = Convert.ToDouble( args.Position.Coordinate.Altitude.ToString());
        dPrevLongitude = Convert.ToDouble(args.Position.Coordinate.Longitude.ToString());
        dPrevLatitude = Convert.ToDouble(args.Position.Coordinate.Latitude.ToString());
    }

1 个答案:

答案 0 :(得分:0)

启用互联网功能后解决了问题。