gpt4 book ai didi

c# - C#获取当前位置的经纬度

转载 作者:行者123 更新时间:2023-11-30 20:22:56 25 4
gpt4 key购买 nike

我是c#的新手,我尝试获取当前位置的经纬度。以下是我尝试过的代码。

代码

public string GetLocationProperty()
{
double a = 0.0;
string b = "";
GeoCoordinateWatcher watcher = new GeoCoordinateWatcher();

// Do not suppress prompt, and wait 1000 milliseconds to start.
watcher.TryStart(false, TimeSpan.FromMilliseconds(1000));

GeoCoordinate coord = watcher.Position.Location;

if (coord.IsUnknown != true)
{
//Console.WriteLine("Lat: {0}, Long: {1}",
// coord.Latitude,
// coord.Longitude);
a = coord.Latitude;
b = a.ToString();
}
else
{
Console.WriteLine("Unknown latitude and longitude.");
}
return b;
}

最佳答案

给你

GeoCoordinateWatcher watcher= new GeoCoordinateWatcher(GeoPositionAccuracy.Default);
watcher.Start(); //started watcher
GeoCoordinate coord = watcher.Position.Location;
if (!watcher.Position.Location.IsUnknown)
{
double lat = coord.Latitude; //latitude
double long = coord.Longitude; //logitude
}

关于c# - C#获取当前位置的经纬度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30297247/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com