从Windows Phone 8获取国家/地区名称

Sun*_*kor 9 c# windows-phone-7 windows-phone-8

我有截图

在此输入图像描述

我打算找回应该是"尼日利亚"的国家.在完成System.Globalization类之后,我找到了下面的代码片段

System.Globalization.RegionInfo.CurrentRegion.EnglishName
Run Code Online (Sandbox Code Playgroud)

但我得到的是"美国",这是上图所示的"地区格式".我无法检索国家/地区值设置吗?

Sun*_*kor -2

这就是我在一天结束时所做的。首先我使用 Location 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);
            }
        }
Run Code Online (Sandbox Code Playgroud)

然后使用谷歌的反向地理定位根据经度和纬度获取位置的信息或详细信息

http://maps.googleapis.com/maps/api/geocode/json?latlng=latitiude,longitude&sensor=true
Run Code Online (Sandbox Code Playgroud)

即如果纬度为 60,经度为 60

http://maps.googleapis.com/maps/api/geocode/json?latlng=60,60&sensor=true
Run Code Online (Sandbox Code Playgroud)

从 json 结果中,您将能够检索该国家/地区的长名称和短名称。