如何在Net Core 7.0 WinForms中获取当前GPS位置

问题描述 投票:0回答:1

有没有办法获取 Net core 7.0 Winforms 应用程序上的当前位置,以便在 DevExpress 组件映射中打印?

我的应用程序的许多用户都可以进行移动工作,他们需要打开带有 devexpress 地图的表单并指出他们的位置并查看周围有哪些客户。所以我需要获取他们的笔记本电脑位置。在.net框架上有GeoCooperativeWatcher类,但我在net core 7中没有看到任何等效的类。

c# location
1个回答
0
投票

安装必要的NuGet包: 使用系统; 使用系统.设备.位置;

公共分部类MainForm:表单 { 私人地理坐标观察者_watcher;

public MainForm()
{
    InitializeComponent();

    _watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.Default);
    _watcher.PositionChanged += Watcher_PositionChanged;
    _watcher.Start();
}

private void Watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
    double latitude = e.Position.Location.Latitude;
    double longitude = e.Position.Location.Longitude;

    // Do something with the latitude and longitude values (e.g., display them in TextBoxes)
    textBoxLatitude.Text = latitude.ToString();
    textBoxLongitude.Text = longitude.ToString();
}

}

根据你的逻辑修改

© www.soinside.com 2019 - 2024. All rights reserved.