You could refer to the following methods to get the latitude and longitude and save it to the database.
The code of xaml:
<StackPanel>
<TextBox Name="txtId" Width="200" Height="30"></TextBox>
<TextBox Name="txtLatitude" Width="200" Height="30"></TextBox>
<TextBox Name="txtLongitude" Width="200" Height="30"></TextBox>
<Button Name="load" Click="load_Click">load</Button>
</StackPanel>
The code of xaml.cs:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
GetLocationEvent();
}
GeoCoordinateWatcher watcher;
public void GetLocationEvent()
{
this.watcher = new GeoCoordinateWatcher();
this.watcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(watcher_PositionChanged);
bool started = this.watcher.TryStart(false, TimeSpan.FromMilliseconds(20000));
}
void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
PrintPosition(e.Position.Location.Latitude, e.Position.Location.Longitude);
}
void PrintPosition(double Latitude, double Longitude)
{
MessageBox.Show("latitude" + Latitude + "longitude" + Longitude);
txtLatitude.Text = Latitude.ToString();
txtLongitude.Text = Longitude.ToString();
}
private void load_Click(object sender, RoutedEventArgs e)
{
SqlConnection con = new SqlConnection(@"constr");
SqlCommand cmd = new SqlCommand(@"INSERT INTO [dbo].[LocationTable]([Id],[Latitude],[Longitude])VALUES('" + int.Parse(txtId.Text) + "','" + float.Parse(txtLatitude.Text)+"','"+float.Parse(txtLongitude.Text)+"')",con);
con.Open();
cmd.ExecuteNonQuery();
MessageBox.Show("Data created successfully");
con.Close();
}
}
The picture of result:

If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our [documentation][5] to enable e-mail notifications if you want to receive the related email notification for this thread.
[5]: https://learn.microsoft.com/en-us/answers/articles/67444/email-notifications.html