从Windows 8手机获得国家/地区名称 [英] Get Country/Region name from windows phone 8
问题描述
我有截图
和我打算恢复这应该是国家尼。通过System.Globalization类去后,我发现下面
and I am intending to retrieve the country which should be "Nigeria". After going through the System.Globalization class, I found the code snippet below
System.Globalization.RegionInfo.CurrentRegion.EnglishName
但我正在逐渐美,这是区域格式,从上面的图片。请问有没有什么办法可以检索国家/地区值设置吗?
But I am getting "United States", which is the "Regional Format" from the image above. Is there no way i can retrieve the Country/Region value settings?
推荐答案
这是我做过什么在一天结束。首先,我使用了位置API库来获取位置的坐标(经度和纬度)
This is what i did at the end of the day. First I used the Location API library to get the coordinates(longitude and latitude) of the location
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);
}
}
然后使用谷歌的反向地理定位来获取信息或细节基于经度和纬度
then using google's reverse geolocation to get the information or details of the location based on the longitude and latitude
http://maps.googleapis.com/maps/api/geocode/json?latlng=latitiude,longitude&sensor=true
即
http://maps.googleapis.com/maps/api/geocode/json?latlng=60,60&sensor=true
从JSON结果,你就可以检索全国的长期和短期的名字。
From the json result, you will be able to retrieve the country's long and short name.
这篇关于从Windows 8手机获得国家/地区名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!