c#系统设备位置正常工作

时间:2016-08-08 19:17:54

标签: c# windows geolocation

我的代码应该可以用来获取位置感知,并且它确实工作了一段时间但最近没有对代码进行任何更改,GeoPositionStatus等于NoData。位置服务已经开启,几天前这项工作非常顺利,此后一切都没有改变。那为什么现在不工作呢?有什么建议?计算机是Windows 10,设备的位置已开启。

    static GeoCoordinateWatcher _watcher;
    /// <summary>
    ///
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        //Application.Run(new Form1());
        _watcher = new GeoCoordinateWatcher();
        _watcher.StatusChanged += Watcher_StatusChanged;
        _watcher.PositionChanged += GeoPositionChanged;

        _watcher.Start();
        Thread.Sleep(500);
        var coord = _watcher.Position.Location;
    }

    private static void Watcher_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
    {
        if (e.Status == GeoPositionStatus.Ready)
        {
            MessageBox.Show("Watcher is ready. First location: The current location is: " +
          _watcher.Position.Location.Latitude + "/" +
          _watcher.Position.Location.Longitude + ".");
        }
    }

    private static void GeoPositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
    {
        MessageBox.Show("The current location is: " +
            e.Position.Location.Latitude + "/" +
            e.Position.Location.Longitude + ".");
    }

0 个答案:

没有答案