我有这个截图:
我打算获取应该是“尼日利亚”的国家名称。在查阅了System.Globalization类之后,我找到了下面的代码片段:
System.Globalization.RegionInfo.CurrentRegion.EnglishName
但是我得到的是“美国”,这是上面图像中的“区域格式”。有没有办法检索国家/地区值设置?
我有这个截图:
我打算获取应该是“尼日利亚”的国家名称。在查阅了System.Globalization类之后,我找到了下面的代码片段:
System.Globalization.RegionInfo.CurrentRegion.EnglishName
但是我得到的是“美国”,这是上面图像中的“区域格式”。有没有办法检索国家/地区值设置?
我知道这篇文章已经有点老了,但是也许有人来到这里寻找答案:
System.Globalization.RegionInfo.CurrentRegion.TwoLetterISORegionName
US
而不是 美国
。此外,问题似乎是关于为什么 OP 没有得到他期望的名称。 - p.s.w.g用户所询问的正确答案是:
Windows.System.UserProfile.GlobalizationPreferences.HomeGeographicRegion
这应该为您提供有关“语言+地区”设置中的国家/地区选择的信息。
试试这个
System.Globalization.RegionInfo.CurrentRegion.DisplayName;
使用System.Threading.Thread.CurrentThread.CurrentCulture.
它应该正确地反映手机语言。
这是我在一天结束时所做的事情。首先,我使用了位置API库来获取该位置的坐标(经度和纬度)。
Geolocator geolocator = new Geolocator();
geolocator.DesiredAccuracyInMeters = 50;
try
{
// Request the current position
Geoposition geoposition = await geolocator.GetGeopositionAsync(
maximumAge: TimeSpan.FromMinutes(5),
timeout: TimeSpan.FromSeconds(10)
);
string latitude = geoposition.Coordinate.Latitude.ToString("0.00");
string longitude = geoposition.Coordinate.Longitude.ToString("0.00");
}
catch (Exception ex)
{
if ((uint)ex.HResult == 0x80004004)
{
// the application does not have the right capability or the location master switch is off
MessageBox.Show("Location is disabled in phone settings.", "Can't Detect Location", MessageBoxButton.OK);
}
//else
{
// something else happened acquring the location
System.Diagnostics.Debug.WriteLine(ex.Message);
}
}
http://maps.googleapis.com/maps/api/geocode/json?latlng=latitiude,longitude&sensor=true
例如,如果纬度为60,经度为60
http://maps.googleapis.com/maps/api/geocode/json?latlng=60,60&sensor=true